<?php
namespace App\Controller;
use App\Entity\Account;
use App\Entity\ApiInboundTraffic;
use App\Entity\ApiLeadsLogs;
use App\Entity\CampaignThankYou;
use App\Service\Blacklists\WordsBlackList\WordsBlackListService;
use App\Entity\ListLeadChecks;
use App\Entity\ProjectFilterLog;
use App\Entity\Wslog2;
use App\Entity\DoiLogs;
use App\Entity\EmailSetUp;
use App\Service\Utilities\EmailService;
use App\Service\CampaignService\CampaignService;
use App\Entity\PageType;
use App\Entity\Ping;
use App\Entity\Pingfield;
use App\Entity\Post;
use App\Entity\ServerToServer;
use App\Entity\ServerToServerLog;
use App\Entity\ThankYou;
use App\Entity\UniqueEmails;
use App\Entity\UniquePhone;
use App\Entity\WslogCallType;
use App\Entity\WslogInboundPing;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\Lead;
use App\Entity\Session;
use App\Entity\Campaign;
use App\Entity\Company;
use App\Entity\Project;
use App\Entity\Fieldcampaign;
use App\Entity\Field;
use App\Entity\Leadfield;
use App\Entity\Leadcampaign;
use App\Entity\Ws;
use App\Entity\Wslog;
use App\Entity\Lang;
use App\Entity\Country;
use App\Entity\Leadstatus;
use App\Entity\Hasoffers;
use App\Entity\Filter;
use App\Entity\Filtergroup;
use App\Entity\Filtercampaign;
use App\Entity\Filtercampaigngroup;
use App\Entity\Page;
use App\Entity\Projectmail;
use App\Entity\Campaignfilterlog;
use App\Entity\Header;
use App\Entity\Fraudstatus;
use App\Entity\Antifraud;
use App\Entity\Status;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\RadioType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Doctrine\ORM\EntityRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use stdClass;
use App\Form\Type\CustomFieldcampaignType;
use App\Form\Type\CustomFieldcampaign2Type;
use App\Form\Type\CustomFieldprojectType;
use App\Form\Type\CustomFieldproject2Type;
use App\Form\Type\ProjectType;
use App\Form\Type\MultipleFieldsType;
use Symfony\Component\Validator\Constraints\DateTime;
use App\Controller\AppOpticksController;
use App\Entity\Processtatus;
class ApiController extends AbstractController
{
private $testlead = false;
private $testwebservice = false;
private $honeypotcheck ;
private $invalidemailcheck ;
private $duplicatelephone ;
private $duplicateemail ;
private $campaignsconnected ;
private $blacklistedcheck, $mandatoryfields, $fieldrules ;
public function __construct(EmailService $emailService, CampaignService $campaignService,WordsBlackListService $wordBlackListService) {
$this->emailService = $emailService;
$this->campaignService = $campaignService;
$this->wordsBlackListService = $wordBlackListService;
}
public function subscribe(Request $request) {
// Mapping base Data
$data = $request->request->all();
$em = $this->getDoctrine()->getManager();
// Set test variable
$data['test'] = false;
$testlead = false;
$testwebservice = false;
// Set result array
$resultin = array(
'honeypot' => false,
'inactive' => false,
'invalidemail' => false,
'invaliddomain' => false,
'duplicategen' => false,
'duplicate' => false,
'duplicatetracking' => false,
'invalidtracking' => false,
'fake' => false,
'validproject' => false,
'inserted' => false,
'novalidproject' => false,
'api_project' => false,
'duplicateemailproject' => false,
'roifail' => false,
'blacklist' => false,
);
$resultout = array(
'validcampaign' => false,
'validcustomer' => false
);
$revenue = 0;
$sold = 0;
$active = $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
$inboundcalllog = $this->inboundcalllog($request->headers, $request->request->all()); // create a new log for inbound call
//Delete after code something to block sources
if (isset($data['source'])) {
if ($data["source"] == "2871"){
$resultin['novalidproject'] = true;
$result = $this->feedback($resultin, $resultout);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result));
return $this->json($result);
}
}//
// Set project variable
if (isset($data['project'])) {
$project_id = $data['project'];
} else { // No project set in the data payload
$resultin['novalidproject'] = true;
$result = $this->feedback($resultin, $resultout);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result));
return $this->json($result);
}
// Check if project exist and it's active. If not return
$project = $this->getDoctrine()->getRepository(Project::class)->findOneById($project_id);
if ($this->getUser()->getId() == 9){
dd("oiuhasd");
}
if ($project == null) { // No project found
$resultin['api_project'] = true;
$result = $this->feedback($resultin, $resultout);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result));
return $this->json($result);
} elseif($project->getStatus()->getId() == 9) { // project in test status
//affiliates
if ($this->getUser()->getId() !== 2 && $this->getUser()->getProject()->contains($project) !== true) {
$resultin['api_project'] = true;
$result = $this->feedback($resultin, $resultout);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result));
return $this->json($result);
}
$test = $this->getDoctrine()->getRepository(Status::class)->findOneById(9);
$resultin['validproject'] = true;
$resultin['inserted'] = true;
$resultin['validcampaign'] = true;
$resultout['validcampaign'] = true;
$resultout['validcustomer'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(18);
$fields = $this->getDoctrine()->getRepository(Field::class)->findBy(
array(
'project' => $project,
'status' => $active
)
);
// Notify test lead to tracking platform
try {
$lead = $this->insertlead($data, $project, $lead_status);
$leadfield = $this->leadfield($fields, $data, $lead);
/*$url = 'https://loudingads.api.hasoffers.com/Apiv3/json?NetworkToken=NETfLjuz52LTPJ2aOWXOruj7Lo7u7l&Target=Conversion&Method=create&data[offer_id]='.$data["offer"].'&data[affiliate_id]='.$data["source"].'&data[revenue]=0&data[payout]=0&data[affiliate_info5]=test';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);*/
} catch (\Exception $e){
$result = array(
'code' => 404,
'success' => false,
'message' => 'Problem inserting the lead',
'lead id' => $lead->getId()
);
return $this->json($result);
}
//checkMandarotyFields
$mandatorycheck = $this->checkMandarotyFields($lead,$fields);
if ($mandatorycheck !== ''){
$result = $this->customFeedback(404,false,$mandatorycheck,$lead->getId());
//return no all mandatory fields were filled
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20); // Filter project fail
$lead->setStatus($lead_status);
$em->persist($lead);
$em->flush();
$this->mandatoryfields = false;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
$this->mandatoryfields = true;
//endchecheckingMandatoryFields
try {
$checkfieldsrules = $this->checkFieldsRules($lead,$fields);
if ($checkfieldsrules != ""){
$result = $this->customFeedback(404,false,$checkfieldsrules,$lead->getId());
//return rules fields no succeded
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20); // Filter project fail
$lead->setStatus($lead_status);
$em->persist($lead);
$em->flush();
$this->fieldrules = false;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
}catch (\Exception $e){
}
$this->fieldrules = true;
$price = '0';
if ($this->getUser()->getId() !== 2 && $this->getUser()->getProject()->contains($project) !== true) {
$result = array(
'code' => 404,
'success' => false,
'message' => 'Contact us to change your permissions',
'lead id' => $lead->getId()
);
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20);
$lead->setStatus($lead_status);
$em->persist($lead);
$em->flush();
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result);
}
if (($project->getTracking() !== null && $project->getTracking()->getId() == '1') || $project->getProjectEverflow() == null){
$result = array(
'code' => 404,
'success' => false,
'message' => 'Contact us to change tracking set up',
'lead_id' => $lead->getId()
);
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20);
$lead->setStatus($lead_status);
$em->persist($lead);
$em->flush();
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result);
} elseif ($project->getProjectEverflow() != null){
if ($project->getProjectEverflow() !== null) {
//if project has everflow connection(API projects mainly) we set up source and offer
$data["source"] = (string)$project->getProjectEverflow()->getSource();
$data["offer"] = (string)$project->getProjectEverflow()->getOffer();
}
if ($lead->getProject()->getRevenueShare() == true){
if (isset($data["clickid"])){
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId(),"price"=>$price))->getContent();
}elseif(isset($data["source"]) && isset($data["offer"])){
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId(),"price"=>$price))->getContent();
}else{
$tracking = false;
}
}else{
if (isset($data["clickid"])){
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
}elseif(isset($data["source"]) && isset($data["offer"])){
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
}else{
$tracking = false;
}
}
if ($tracking == "true"){ // Tracking process accepted
// Set up cost
try {
if ($project->getRevenueShare() == true){ // Project on Revenue share: the cost is calculated internally
if ($project->getCommissions() == 0){
$commission = 1;
}else{
$commission = $project->getCommissions();
}
$cost = ($price*$commission)/100;
}else{ // Project on fixed CPL: the cost is taken from the tracking system setup for each publisher
$cost = $this->forward('App\Controller\EverFlowController::retrieveCost', array("offer" => $data["offer"], "affid" => $data["source"]))->getContent();
if (json_decode($cost)->cost == 0 && $project->getProjectEverflow() == null){
$cost = $this->forward('App\Controller\EverFlowController::retrieveCostOffer', array("offer" => $data["offer"]))->getContent();
}else{
$cost = array(
"cost" => 0
);
$cost=json_encode($cost);
}
$cost = json_decode($cost)->cost;
}
}catch (\Exception $e){
$cost = 0;
}
$lead->setCost(floatval($cost));
} else { // Tracking process rejected
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6);
$lead->setStatus($lead_status); // duplicate lead
$resultin['invalidtracking'] = true;
}
}
$result = $this->feedback($resultin, $resultout, $lead, $price);
if ($project->getStatus()->getId() == 9) {
if ($result["message"] == "valid user") {
$result["message"] = "valid test";
}
}
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
} elseif($project->getStatus()->getId() !== 1) { // project not active
$resultin['api_project'] = true;
$result = $this->feedback($resultin, $resultout);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result));
return $this->json($result);
} else {
// Check if the user api is allowed to insert lead in this project
if ($this->getUser()->getId() !== 2 && $this->getUser()->getProject()->contains($project) !== true) {
$resultin['api_project'] = true;
$result = $this->feedback($resultin, $resultout);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result));
return $this->json($result);
}
}
// Set email variable
if (isset($data['email'])) {
$email = strtolower(trim($data['email']));
} else {
$email = null;
}
// Set test variables
try {
if (isset($email)){
if (str_contains($email, '@loudingads.com') == true ) { // lead sent to tracking but not sent to campaigns
$data['test'] = true;
$testlead = true;
$this->setTestlead(true);
}elseif (str_contains($email, '@loudingest.com') == true) { // lead sent only to campaigns in test status
$data['test'] = true;
$testwebservice = true;
$this->setTestwebservice(true);
}
}
} catch (\Exception $e) {
}
// Check if user is a bot
if (isset($data['honeypot'])){
if ($data['honeypot'] !== null && $data['honeypot'] !== ''){
$resultin['validproject'] = true;
$resultin['honeypot'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(19); // bot
$lead = $this->insertlead($data, $project, $lead_status);
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
$this->honeypotcheck = false ;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
}
$this->honeypotcheck = true ;
// Check if email is valid
$emailcheck = $this->emailcheck($email);
if ($emailcheck == 2 || $emailcheck == 3) {
if (str_contains($data['email'], '@outlook.es') == false && str_contains($data['email'], '@telefonica.net') == false && str_contains($data['email'], '@kpnplanet.nl') == false && str_contains($data['email'], '@upcmail.nl') == false) {
if ($emailcheck == 2) {
$resultin['invalidemail'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(9); // invalid email
}elseif ($emailcheck == 3) {
$resultin['invaliddomain'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(10); // invalid domain dns
}
$this->invalidemailcheck = false;
$lead = $this->insertlead($data, $project, $lead_status);
$this->listleadchecks($lead);
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
}
$this->invalidemailcheck = true;
// Check blacklist
foreach ($project->getBlackLists() as $blacklist){
if ($blacklist->getStatus()->getId() == 1){
$conn = $em->getConnection();
$query = 'select * from blacklist_' .$blacklist->getId(). ' where email=? ';
$stmt = $conn->prepare($query);
if ($blacklist->getType() == 'md5'){
$stmt->bindValue(1, md5($email), 'string');
}else{
$stmt->bindValue(1, hash( 'SHA256', $email), 'string');
}
$stmt->execute();
if (sizeof($stmt->fetchAll()) > 0) { // user is in blacklist
$resultin['blacklist'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(17); // black list
$lead = $this->insertlead($data, $project, $lead_status);
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
$this->blacklistedcheck = false;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
}
}
$this->blacklistedcheck = true;
// Check if email is already registered in db
$uniqueemail = $this->getDoctrine()->getRepository(UniqueEmails::class)->findByEmail($email);
if (count($uniqueemail) > 0) { // duplicate in the system. the lead can still be passed to other products
// Check if email is already registered in the project
$leadproject = $this->getDoctrine()->getRepository(Lead::class)->findBy(
array(
'email' => $email,
'project' => $project
)
);
if (count($leadproject) > 0) {
$resultin['duplicateemailproject'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6); // duplicate for this project
$lead = $this->insertlead($data, $project, $lead_status);
// Not passed to customers
$fields = $this->getDoctrine()->getRepository(Field::class)->findBy(
array(
'project' => $project,
'status' => $active
)
);
$leadfield = $this->leadfield($fields, $data, $lead);
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
$this->duplicateemail = false;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
$resultin['duplicategen'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(14);
// If the email belongs to the Project Zonnepanelen NL and it's duplicate in the script won't go ahead. Same behaviour as duplicate project
/*if($project->getLabel()->getId() == 8 && $project->getId() == 14 || $project->getId() == 25 || $project->getId() == 32 || $project->getId() == 36 || $project->getId() == 101 || $project->getId() == 114 || $project->getId() == 117 || $project->getId() == 121 || $project->getId() == 134 || $project->getId() == 140 || $project->getId() == 147 || $project->getId() == 160 || $project->getId() == 167 ) {*/
// If the lead belongs to the same project label it's duplicate and won't be passed to the customers
$repository = $this->getDoctrine()->getRepository(Lead::class);
$query = $repository->createQueryBuilder('l');
//$query->addSelect('count(l.id)');
$query->leftJoin('App:Project', 'p', 'WITH', 'l.project = p.id');
$query->leftJoin('App:LabelProject', 'lb', 'WITH', 'p.label = lb.id');
$query->andWhere('l.email = :email');
$query->andWhere('lb.id = :label');
$query->setParameter('email', $email);
$query->setParameter('label', $project->getLabel()->getId());
$query = $query->getQuery();
$label_duplicate = $query->getResult();
if(count($label_duplicate) > 0) { // duplicate for the same product the lead won't be passed
$resultin['duplicateemailproject'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6); // duplicate for this project
$lead = $this->insertlead($data, $project, $lead_status);
// Not passed to customers
$fields = $this->getDoctrine()->getRepository(Field::class)->findBy(
array(
'project' => $project,
'status' => $active
)
);
$leadfield = $this->leadfield($fields, $data, $lead);
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
$this->duplicateemail = false;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
} else { // not duplicate
$uniqueemail = new UniqueEmails();
$uniqueemail->setEmail($email);
$em->persist($uniqueemail);
$em->flush();
}
$this->duplicateemail = true;
if (isset($data['phone'])) {
$phone = strval(str_replace(' ','',$data['phone']));
} else {
$phone = null;
}
//check blacklisted phone
try{
if ($this->testlead == false && $this->testwebservice == false){
foreach ($project->getPhoneBlackLists() as $phoneblacklist){
if ($phoneblacklist->getStatus()->getId() == 1){
$conn = $em->getConnection();
$query = 'select * from phoneblacklist_' .$phoneblacklist->getId(). ' where phone=? ';
$stmt = $conn->prepare($query);
if ($blacklist->getType() == 'md5'){
$stmt->bindValue(1, md5($phone), 'string');
}else{
$stmt->bindValue(1, hash( 'SHA256', $phone), 'string');
}
$stmt->execute();
if (sizeof($stmt->fetchAll()) > 0) { // user is in blacklist
$resultin['blacklist'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(17); // black list
$lead = $this->insertlead($data, $project, $lead_status);
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
$this->blacklistedcheck = false;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
$this->blacklistedcheck = true;
}
}
}
} catch(\Exception $e) {
//if the code inside the try doesnt work will keep the flow
}
if ($this->wordsBlackListService->containsBlacklistedWord($data)) {
$resultin['blacklist'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(17); // black list
$lead = $this->insertlead($data, $project, $lead_status);
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
$this->blacklistedcheck = false;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
// Check if phone is already registered in db
if($this->testlead == false && $this->testwebservice == false) { // check double phone only if it's not a test
$uniquephone = $this->getDoctrine()->getRepository(UniquePhone::class)->findByPhone($phone);
if (count($uniquephone) > 0) { // duplicate in the system. the lead can still be passed to other products
// Check if phone is already registered in the project
$leadproject = $this->getDoctrine()->getRepository(Lead::class)->findBy(
array(
'phone' => $phone,
'project' => $project
)
);
if (count($leadproject) > 0) {
$resultin['duplicateemailproject'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(15); // duplicate for this project
$lead = $this->insertlead($data, $project, $lead_status);
// Not passed to customers
$fields = $this->getDoctrine()->getRepository(Field::class)->findBy(
array(
'project' => $project,
'status' => $active
)
);
$leadfield = $this->leadfield($fields, $data, $lead);
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
$this->duplicatelephone = false;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
$resultin['duplicategen'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(14);
// If the lead belongs to the same project label it's duplicate and won't be passed to the customers
$repository = $this->getDoctrine()->getRepository(Lead::class);
$query = $repository->createQueryBuilder('l');
//$query->addSelect('count(l.id)');
$query->leftJoin('App:Project', 'p', 'WITH', 'l.project = p.id');
$query->leftJoin('App:LabelProject', 'lb', 'WITH', 'p.label = lb.id');
$query->andWhere('l.phone = :phone');
$query->andWhere('lb.id = :label');
$query->setParameter('phone', $phone);
$query->setParameter('label', $project->getLabel()->getId());
$query = $query->getQuery();
$label_duplicate = $query->getResult();
if(count($label_duplicate) > 0) { // duplicate for the same product the lead won't be passed
$resultin['duplicateemailproject'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6); // duplicate for this project
$lead = $this->insertlead($data, $project, $lead_status);
// Not passed to customers
$fields = $this->getDoctrine()->getRepository(Field::class)->findBy(
array(
'project' => $project,
'status' => $active
)
);
$leadfield = $this->leadfield($fields, $data, $lead);
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
$this->listleadchecks($lead);
return $this->json($result); // End of process
}
} else { // not duplicate
$uniquephone = new UniquePhone();
$uniquephone->setPhone($phone);
$em->persist($uniquephone);
$em->flush();
}
}
$this->duplicatelephone = true;
// Insert lead
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(1); // active email
$lead = $this->insertlead($data, $project, $lead_status);
/* if (isset($data["tokenrecaptcha"])){
$this->forward('App\Controller\RecaptchaController::saveAPIResponse', array('data' => $data, 'lead' =>$lead));
}*/
if ($lead == null) { // If lead insertion fails
// Not passed to customers
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
} else {
$resultin['inserted'] = true;
}
// Validate and set custom fields
// Get fields of the project
$fields = $this->getDoctrine()->getRepository(Field::class)->findBy(
array(
'project' => $project,
'status' => $active
)
);
// Insert custom field
$leadfield = $this->leadfield($fields, $data, $lead);
//checkMandarotyFields
$mandatorycheck = $this->checkMandarotyFields($lead,$fields);
if ($mandatorycheck != ""){
$result = $this->customFeedback(404,false,$mandatorycheck,$lead->getId());
//return no all mandatory fields were filled
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20); // Filter project fail
$lead->setStatus($lead_status);
$em->persist($lead);
$em->flush();
$this->mandatoryfields = false;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
$this->mandatoryfields = true;
//endchecheckingMandatoryFields
try {
$checkfieldsrules = $this->checkFieldsRules($lead,$fields);
if ($checkfieldsrules != ""){
$result = $this->customFeedback(404,false,$checkfieldsrules,$lead->getId());
//return no all mandatory fields were filled
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20); // Filter project fail
$lead->setStatus($lead_status);
$em->persist($lead);
$em->flush();
$this->fieldrules = false;
$this->listleadchecks($lead);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
}
}catch (\Exception $e){
}
$this->fieldrules = true;
// DOI
if ($project->getDoi() !== 0 && $project->getDoi() !== null ){
$laststatus = $lead->getStatus();
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(18);
if (($lead->getStatus()->getId()!=1 && $lead->getStatus()->getId()!=2) || str_contains($data['email'], '@test.com') || $this->testlead == true){
$lead->setStatus($lead_status);
}
if($lead->getStatus()->getId()==1 || $lead->getStatus()->getId()==2 || $lead->getStatus()->getId()==18){
$setUps = $this->getDoctrine()->getRepository(EmailSetUp::class)->findby(
array(
'project' => $project->getId(),
'status' => 1
)
);
/*if (str_contains($data['email'], '@loudingads.com') == true){
dd("holi");
}*/
if (count($setUps) != 0 ){
$setUp = $setUps[count($setUps)-1];
/* if (str_contains($lead->getEmail(), '@test.com') == true || str_contains($lead->getEmail(),'@loudingads.com' == true)){
$emailchanged = $data['email'];
$data['email'] = "lennard.loudingads@gmail.com";
$lead->setEmail("lennard.loudingads@gmail.com");
$changeemail=true;
}*/
$doidata['url'] = $data['referral'];
$doidata["version"] =substr($doidata['url'],0,(stripos($doidata['url'],"/v")+4));
$doidata['lead'] = $lead->getId();
$doidata['encryptedlead'] = openssl_encrypt(
$lead->getId(),
"aes128",
"vLjow7178",
0,
$iv="7983248923794221" );
$doidata['sendto'] = $lead->getEmail();
//if ( ($project->getId() !=23 ) ||($project->getId()==23 && (str_contains($data['email'], '@test.com') == true || str_contains($data['email'], 'loudingads') == true))) {
switch ($setUp->getEmailsetuptype()->getId()) {
case 1: //
$result = $this->forward('App\Controller\DoiServiceController::SMTP', array('emailsetupid' => $setUp->getId(), "doidata" => $doidata))->getContent();
break;
}
}
}
$lead->setStatus($laststatus);
}
// Check if custom field are valid with Filter project
$resultin['validproject'] = $this->checkfilter($lead);
if ($resultin['validproject'] == false) { // checkfilter is false
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(12); // Filter project fail
$lead->setStatus($lead_status);
$em->persist($lead);
$em->flush();
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
$this->listleadchecks($lead);
return $this->json($result); // End of process
}
// Set test mode for antifraud
try {
$antifraud = $this->antifraud($lead,$data); // return fraud status
} catch(\Exception $e) {
}
// Check all the Campaigns available for this Project
$repository = $this->getDoctrine()->getRepository(Campaign::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->leftJoin('App:Status', 's', 'WITH', 'c.status = s.id');
$query->leftJoin('App:LeadVerification', 'lv', 'WITH', 'c.sending = lv.id');
$query->leftJoin('App:sensibility', 'sy', 'WITH', 'c.sensibility = sy.id');
$query->andWhere(':project MEMBER OF c.project');
$query->setParameter('project', $project->getId());
$query->andWhere('s.id = :status'); // Exclude inactive campaign
if (str_contains($lead->getEmail(), '@loudingest.com') == true){ // Get only Test campaign
$query->setParameter('status', 9);
}else{
$query->setParameter('status', 1); // Get only active campaign
}
$query->andWhere('lv.id = :verification');
$query->setParameter('verification', 1); // soi or doi
// Antifraud exclusion
if( $this->testwebservice != true && $this->testlead != true && isset($antifraud) && $antifraud !== null ) { // Apply Sensibility only if the Lead has an antifraud check
if($antifraud->getStatus()->getId() == 2) { // suspicious, not for high sensibility
$query->andWhere('sy.id != :sensibility');
$query->setParameter('sensibility', 1);
} elseif($antifraud->getStatus()->getId() == 4) { // undefined, only for low sensibility campaigns
$query->andWhere('sy.id = :sensibility');
$query->setParameter('sensibility', 3);
} elseif($antifraud->getStatus()->getId() == 3) { // invalid, only for low sensibility campaigns
$query->andWhere('sy.id = :sensibility');
$query->setParameter('sensibility', 3);
}
}
//$query->orderBy('c.id','ASC');
$query->addOrderBy('c.priority','DESC'); // the higher the better
$query->addOrderBy('c.price','DESC'); // the higher the better
$query = $query->getQuery();
$campaigns = $query->getResult();
/*if (str_contains($lead->getEmail(), '@loudingest.com') == true){
dd(count($campaigns),$project,$lead->getEmail(),$this->testwebservice);
}*/
$validate = 1;
/*if (str_contains($lead->getEmail(), '@loudingest.com') == true){
$campaigns = $this->getDoctrine()->getRepository(Campaign::class)->findOneById(381);
}*/
$this->campaignsconnected = $this->campaignsconnected($lead->getProject());
//$this->setTestlead(false);
if (count($campaigns) == 0 && $this->testlead !== true) { // No Campaign available and no test email
$resultout = null;
$revenue = 0;
$sold = 0;
$resultin['roifail'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(16); // roi fail
$lead->setStatus($lead_status); // roi not reached
$em->persist($lead);
$em->flush();
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
$this->listleadchecks($lead);
return $this->json($result); // End of process
} else {
if ($this->testlead !== true) { // Not test email
// Export to campaign
// If the project is pingpost (2)
if ( $project->getProjectType()->getId() == 2 && ( $project->getId() == 176 || $project->getId() == 100 || $project->getId() == 81 || $project->getId() == 139)) {
//new function for ping creation ping etc etc
//delete after
/* $query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->leftJoin('App:Status', 's', 'WITH', 'c.status = s.id');
$query->leftJoin('App:LeadVerification', 'lv', 'WITH', 'c.sending = lv.id');
$query->leftJoin('App:sensibility', 'sy', 'WITH', 'c.sensibility = sy.id');
$query->andWhere(':project MEMBER OF c.project');
$query->setParameter('project', $project->getId());
$query->andWhere('s.id = :status'); // Exclude inactive campaign
$query->setParameter('status', 9);
$query = $query->getQuery();
$campaigns = $query->getResult();*/
//delete before this point
$process_active = $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(1);
$apiinboundtraffic = $this->setApiInboundTraffic($request); // register inbound call status active
$apiinboundtraffic->setProject($project);
$ping = $this->insertping($data, $project, $process_active, $apiinboundtraffic);
$fieldsping = $this->getDoctrine()->getRepository(Field::class)->findBy(
array(
'project' => $project,
'status' => $active
)
);
try {
$this->pingfield($fieldsping, $data, $ping); // register ping custom fields
} catch(\Exception $e) {
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(16);
$lead->setStatus($lead_status);
$resultin['pingsrejected'] = true;
$em->persist($lead);
$em->flush();
$result = $this->clientfeedback($resultin,$apiinboundtraffic,$ping,$price = 0);
return $this->json($result);
}
$singlesell = $this->sellping($lead,$project,$campaigns,$this->testwebservice,$ping,$apiinboundtraffic);
if (isset($singlesell["success"]) && $singlesell["success"] == true) {
$postsinglesell = $this->sellpost($project,$data,$apiinboundtraffic,$ping,$lead);
if (count($postsinglesell)>0) {
if ($postsinglesell["check"] == 1) {
$resultout['revenue'] = $postsinglesell["price"];
$resultout['sold'] = 1;
$resultout['validcampaign'] = true;
$resultout['validcustomer'] = true;
}else{
$resultout['revenue'] = 0;
$resultout['sold'] = 0;
$resultout['validcampaign'] = true;
$resultout['validcustomer'] = false;
}
} else {
$resultin['leadrejected'] = true;
$result = $this->clientfeedback($resultin,$apiinboundtraffic,$lead);
$this->listleadchecks($lead);
return $this->json($result);
}
} else {
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(16);
$lead->setStatus($lead_status);
$resultin['pingsrejected'] = true;
$em->persist($lead);
$em->flush();
$this->listleadchecks($lead);
$result = $this->clientfeedback($resultin,$apiinboundtraffic,$ping,$price = 0);
return $this->json($result);
}
} else { // Direct Post Project
$resultout = $this->export($lead, $project, $campaigns);
}
$revenue = $resultout['revenue'];
$sold = $resultout['sold'];
$lead->setRevenue($revenue);
if ($lead->getRevenue() < $project->getRoi() && !$this->testwebservice) { // Check the ROI
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(16); // roi fail
$lead->setStatus($lead_status); // roi not reached
$resultin['roifail'] = true;
$em->persist($lead);
$em->flush();
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
$this->listleadchecks($lead);
return $this->json($result); // End of process
}
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // valid lead
$lead->setStatus($lead_status); // roi reached
$price = null; // the value we user to calculate the return to the publisher with his commission
if ($lead->getProject()->getRevenueShare() == true) {
$leadscampaigns = $this->getDoctrine()->getRepository(Leadcampaign::class)->findBy(array(
'lead' => $lead->getId(),
));
$prices=[];
foreach ($leadscampaigns as $leadcampaign) {
if ($leadcampaign->getRevenue() !== 0) {
array_push($prices,$leadcampaign->getRevenue());
}
}
$typerevenue = $lead->getProject()->getTypeRevenueShare();
if ($typerevenue == "lowest") {
$price = min($prices);
} elseif ($typerevenue == "average") {
$price = array_sum($prices)/count($prices);
} elseif ($typerevenue == "highest") {
$price = max($prices);
} elseif ($typerevenue == "roi") {
$price = $project->getRoi();
} else{
$price = 0;
}
}
// Tracking and cost
if ($project->getAppTracking() !== null && $project->getAppTracking()->getId() == 3) { // Everflow
if (isset($resultin['duplicategen']) && !$resultin['duplicategen'] == true){
if ($project->getProjectEverflow() !== null) { // hardcoded offer and source for API Project
//if project has everflow connection(API projects mainly) we set up source and offer
$data["source"] = (string)$project->getProjectEverflow()->getSource();
$data["offer"] = (string)$project->getProjectEverflow()->getOffer();
}
if ($lead->getProject()->getRevenueShare() == true) { // Revenue share
$price = $lead->getRevenue();
if (isset($data["clickid"])) {
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId(),"price"=>$price))->getContent();
} elseif (isset($data["source"]) && isset($data["offer"])) {
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId(),"price"=>$price))->getContent();
} else {
$tracking = false;
}
} else { // Fixed CPL
if (isset($data["clickid"])) {
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
} elseif (isset($data["source"]) && isset($data["offer"])) {
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
} else {
$tracking = false;
}
}
if ($tracking == 'true') { // The tracking system accepts the conversion
try {
if ($project->getRevenueShare() == true) { // Project on Revenue share: cost calculated by the system
if ($project->getCommissions() == 0){
$commission = 1;
} else {
$commission = $project->getCommissions();
}
$cost = ($price*$commission)/100;
} else { // Project on fixed CPL: cost taken from the tracking system
$cost = $this->forward('App\Controller\EverFlowController::retrieveCost', array('offer' => $data['offer'], 'affid' => $data['source']))->getContent();
if (json_decode($cost)->cost == 0 && $project->getProjectEverflow() == null) { // if there's no specific cost associated to the publisher in Everflow
$cost = $this->forward('App\Controller\EverFlowController::retrieveCostOffer', array('offer' => $data['offer']))->getContent();
$cost = json_decode($cost)->cost;
} else {
$cost = json_decode($cost)->cost;
}
}
} catch (\Exception $e){
$cost = 0;
}
$lead->setCost(floatval($cost));
} else { // The tracking system doesn't accept the conversion
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6);
$lead->setStatus($lead_status); // duplicate lead
$resultin['invalidtracking'] = true;
}
}
} elseif ($lead->getHs() !== null) { // Only if the campaign is tracked in HasOffers
$tracking = $this->hasoffertrk($lead, $data);
if ($tracking !== null) {
if (isset($tracking->response->data->payout)) {
$cost = $tracking->response->data->payout;
if (isset($tracking->response->data->price)) {
$cost = $tracking->response->data->price;
}
if ($cost == null) {
$cost = 0;
}
} else {
$cost = 0;
}
$lead->setCost(floatval($cost));
} else { // If HasOffers reject the lead as duplicate
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6);
$lead->setStatus($lead_status); // duplicate lead
//$resultin['duplicatetracking'] = true;
$resultin['invalidtracking'] = true;
}
} elseif ($price !== 0 && $lead->getHs() == 0){
if ($project->getRevenueShare() == true) {
if ($project->getId() == 80) {
if ($project->getCommissions() == "0" || $project->getCommissions() == null) {
$commission = 1;
} else {
$commission = $project->getCommissions();
}
$hasofferprice = $price * $commission / 100;
$url = 'https://loudingads.api.hasoffers.com/Apiv3/json?NetworkToken=NETfLjuz52LTPJ2aOWXOruj7Lo7u7l&Target=Conversion&Method=create&data[offer_id]='.$data["offer"].'&data[revenue]='.$price.'&data[payout]='.$hasofferprice.'&data[affiliate_id]='.$data["source"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
} else {
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(1);
$lead->setStatus($lead_status); // active lead
}
}
} elseif ($project->getTracking() == null || ($project->getTracking() != null && $project->getTracking()->getId() == 2)) { // no tracking or tracking API Aff
try {
$url = 'https://loudingads.api.hasoffers.com/Apiv3/json?NetworkToken=NETfLjuz52LTPJ2aOWXOruj7Lo7u7l&Target=Offer&Method=getAffiliatePayment&offer_id='.$data["offer"].'&affiliate_id='.$data["source"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$url = 'https://loudingads.api.hasoffers.com/Apiv3/json?NetworkToken=NETfLjuz52LTPJ2aOWXOruj7Lo7u7l&Target=Conversion&Method=create&data[offer_id]='.$data["offer"].'&data[affiliate_id]='.$data["source"].'&data[revenue]='.json_decode($response)->response->data->revenue.'&data[payout]='.json_decode($response)->response->data->payout;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
} catch (\Exception $e){
}
} else {
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(1);
$lead->setStatus($lead_status); // active lead
}
}
// Test mode
if ($this->testlead == true || str_contains($data['email'], '@test.com') == true || $this->testwebservice == true){
if ($this->testlead == true){ // Test email don't send to the customer but notify to the tracking systems
if ($project->getProjectEverflow() !== null){
//if project has everflow connection(API projects mainly) we set up source and offer
if (!isset($data["source"])) {
$data["source"] = (string)$project->getProjectEverflow()->getSource();
}
if (!isset($data["offer"])) {
$data["offer"] = (string)$project->getProjectEverflow()->getOffer();
}
}
if ($lead->getProject()->getRevenueShare() == true){ // Project on Revenue share
if (isset($data["clickid"])){
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
}elseif(isset($data["source"]) && isset($data["offer"])){
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
}else{
$tracking = false;
}
} else { // Project on fixed CPL
if (isset($data["clickid"])){
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
}elseif(isset($data["source"]) && isset($data["offer"])){
$tracking = $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
}else{
$tracking = false;
}
}
if ($tracking == "true"){ // The tracking system has accepted the conversion
// Calculate the cost
try {
if ($project->getRevenueShare() == true){ // Project on Revenue share
if ($project->getCommissions() == 0){
$commission = 1;
}else{
$commission = $project->getCommissions();
}
$cost = 0;
} else { // Project fixed CPL: cost taken from the tracking system publisher's set up
$cost = $this->forward('App\Controller\EverFlowController::retrieveCost', array("offer" => $data["offer"], "affid" => $data["source"]))->getContent();
if (json_decode($cost)->cost == 0 && $project->getProjectEverflow() == null){
$cost = $this->forward('App\Controller\EverFlowController::retrieveCostOffer', array("offer" => $data["offer"]))->getContent();
}else{
$cost = array(
"cost" => 0
);
$cost=json_encode($cost);
}
$cost = json_decode($cost)->cost;
}
}catch (\Exception $e){
$cost = 0;
}
$lead->setCost(floatval($cost));
}else{
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(24);
$lead->setStatus($lead_status); // duplicate lead
$resultin['invalidtracking'] = true;
}
}
$resultin["invalidtracking"] = false;
if ($lead->getStatus()->getId()==1 || $lead->getStatus()->getId()==2){
if ($this->testlead == true ){
$resultout['validcampaign'] = true;
$resultout['validcustomer'] = true;
}
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(18);
$lead->setStatus($lead_status); // active lead
}
}
$em->persist($lead);
$em->flush();
}
/*if (($lead->getStatus()->getId()==1 ) || ( $lead->getStatus()->getId()==2) || ( $lead->getStatus()->getId()==18)){
$this->sendToServer($lead);
}*/
/*if (isset($price)){
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
if (isset($apileadlog)){
$apileadlog->setLead($lead);
$apileadlog->setResponse($result->getContent());
$em->persist($lead);
$em->flush();
}
return $result ;
}*/
$this->listleadchecks($lead);
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
// Update Apileadlogs
$this->inboundcalllog(null, null, $inboundcalllog, json_encode($result), $lead);
return $this->json($result); // End of process
//return $result;
}
public function closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold, $price = 0)
{
$em = $this->getDoctrine()->getManager();
// Update project numbers
$project = $this->updateproject($project, $resultin, $revenue,$sold,$lead);
$em->persist($project);
$em->flush();
// Update project status with Capping
/*if($project->getDailyreach() == $project->getDailycapping()) {
$status = $this->getDoctrine()->getRepository(Status::class)->findOneById(10); // Daily capping reach
$project->setStatus();
}
if($project->getMonthlyreach() == $project->getMonthlycapping()) {
$status = $this->getDoctrine()->getRepository(Status::class)->findOneById(11); // Monthly capping reach
$project->setStatus();
}
if($project->getValid() == $project->getCapping()) {
$status = $this->getDoctrine()->getRepository(Status::class)->findOneById(5); // Capping reached set to paused
$project->setStatus();
}
$em->persist($project);
$em->flush();*/
$result = $this->feedback($resultin, $resultout, $lead, $price);
/* if (str_contains($lead->getEmail(), '@test.com') == true){
dd("hola",$resultout,$resultin,$result);
}*/
return $result;
return $this->json($result);
}
public function export($lead, $project, $campaigns) {
$em = $this->getDoctrine()->getManager();
$status = $this->getDoctrine()->getRepository(Status::class)->findOneById(1); // active
// Array for the final response
$result = array(
'validcampaign' => false,
'validcustomer' => false,
'revenue' => 0,
'sold' => 0
);
// Check exclusivity from the project
if($project->getExclusivity() == 0 || $project->getExclusivity() == null) {
$exclusivity = count($campaigns);
} else {
$exclusivity = $project->getExclusivity();
}
$c = 1; // Campaign counter
foreach ($campaigns as $campaign) {
$response = 0; // Default response for the campaign
// Check if the lead has been already sent to the customer
//if($testlead !== true && $testwebservice !== true) {
//if($this->testlead !== true && $this->testwebservice !== true) { // don't check duplicate for test
if($this->testwebservice !== true) { // check duplicate only for test
$repository = $this->getDoctrine()->getRepository(Leadcampaign::class);
$query = $repository->createQueryBuilder('lc');
$query->leftJoin('App:Campaign', 'c', 'WITH', 'lc.campaign = c.id');
$query->leftJoin('App:Lead', 'l', 'WITH', 'lc.lead = l.id');
$query->andWhere('c.id = :campaign');
$query->andWhere('(l.email = :email or l.phone = :phone)');
$query->setParameter('campaign',$campaign->getId());
$query->setParameter('email',$lead->getEmail());
$query->setParameter('phone',$lead->getPhone());
$query = $query->getQuery();
$leadcampaign = $query->getResult();
if(count($leadcampaign) > 0) { // email or phone already sent to the customer
continue;
}
}
// Get campaign's field
$fieldscampaign = $this->getDoctrine()->getRepository(Fieldcampaign::class)->findBy(
array(
'status' => $status,
'campaign' => $campaign
)
);
$fields = array();
foreach ($fieldscampaign as $fc) {
$repository = $this->getDoctrine()->getRepository(Field::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->andWhere(':fieldcampaign MEMBER OF c.fieldcampaigns');
$query->setParameter('fieldcampaign', $fc->getId());
$query->andWhere('c.project = :project');
$query->setParameter('project', $project->getId());
$query = $query->getQuery();
$field = $query->getResult();
$fcvalue = $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(
array(
'field' => $field,
'lead' => $lead
)
);
if ($fcvalue !== null) {
$fields[$fc->getName()] = $fcvalue->getValue();
} else {
$fields[$fc->getName()] = null;
}
}
$fields["original_lead_id"] = $lead->getId();
// Validate campaign filter
$filterresult = $this->checkcampaignfilter($lead, $campaign);
if (str_contains($lead->getEmail(), '@loudingest.com') == true){
//dd($filterresult,$fields);
}
if ($filterresult == true) { // filter passed
$arraycheck[$campaign->getId()]['filter'] = 1;
if ((str_contains($lead->getEmail(), '@loudingest.com') == true && $campaign->getStatus()->getId() == 9) || (str_contains($lead->getEmail(), '@loudingest.com') == false && $campaign->getStatus()->getId() != 9)) {
if ($campaign->getValidation() == 1) { // If campaign has webservice validation, send lead via ws; fields are campaignfields
switch ($campaign->getId()) {
case 1: // Loudingads leadgen ES
$webservice = $this->forward('App\Controller\WebserviceController::loudingads', array('data' => $fields, 'campaign' => 1))->getContent();
break;
case 431: // Triple Eight Media Debt UK Monetise
$webservice = $this->forward('App\Controller\WebserviceController::tripleeightmedia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 430: // Solar UK Monetise
$webservice = $this->forward('App\Controller\WebserviceController::monetise', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 429: // Kataisa Energia ES
$webservice = $this->forward('App\Controller\WebserviceController::kataisa', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 428: // Claims UK Qubiq
$webservice = $this->forward('App\Controller\WebserviceController::qubiq', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 427: // Maverick SolMedia Limited Solar UK
$webservice = $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 426: // HomeSecurity NL 360 unitedmedia
$webservice = $this->forward('App\Controller\WebserviceController::unitedmedia360', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 425: // Maverick SolMedia Limited Solar UK
$webservice = $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 424: // Iberdrola Energia ES
$webservice = $this->forward('App\Controller\WebserviceController::iberdrola', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 423: // MediaAdgo Energia ES
$webservice = $this->forward('App\Controller\WebserviceController::mediaadgo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 420: // Consumer Insite Debt US
$webservice = $this->forward('App\Controller\WebserviceController::consumerinsite', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 419: // Tresa Energia Solar ES Exclusive
$webservice = $this->forward('App\Controller\WebserviceController::tresa', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 418: // Maverick SolMedia Limited Solar UK
$webservice = $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 417: // Maverick SolMedia Limited Solar UK
$webservice = $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 416: // Maverick SolMedia Limited Solar UK
$webservice = $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 415: // Tresa Energia Solar ES Exclusive
$webservice = $this->forward('App\Controller\WebserviceController::tresa', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 414: // Maverick SolMedia Limited Solar UK
$webservice = $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 413: // Zonnepannelen NL Hilead
$webservice = $this->forward('App\Controller\WebserviceController::hilead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 412: // Debt US Adventum
$webservice = $this->forward('App\Controller\WebserviceController::adventumllcdirect', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
dd($webservice);
break;
case 411: // Zonnepannelen NL Hilead
$webservice = $this->forward('App\Controller\WebserviceController::hilead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 410: // Solar ES Daa Gmbh
$webservice = $this->forward('App\Controller\WebserviceController::daagmbh', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 408: // Solar DE Dlulisa
$webservice = $this->forward('App\Controller\WebserviceController::dlulisa', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 407: // Debt UK Monetise
$webservice = $this->forward('App\Controller\WebserviceController::monetise', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 406: // Zonnepanelen NL Solvari
$webservice = $this->forward('App\Controller\WebserviceController::solvari', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 405: // Paneles Solares ES ExpertaSolar
$webservice = $this->forward('App\Controller\WebserviceController::expertasolar', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 404: // Paneles Solares ES Habitissimo
$webservice = $this->forward('App\Controller\WebserviceController::habitissimo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 403: // Solar NL VipLeads
$webservice = $this->forward('App\Controller\WebserviceController::vipsleads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 402: // Solar ES Voltalia
$webservice = $this->forward('App\Controller\WebserviceController::voltalia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 401: // BEFR Panneaux Solaire Otoads
$webservice = $this->forward('App\Controller\WebserviceController::otoads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 399: // Energia GanaEnergia
$webservice = $this->forward('App\Controller\WebserviceController::ganaenergia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 398: // Energia Repsol T2O
$webservice = $this->forward('App\Controller\WebserviceController::repsolt2o', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 397: // Solar BENL OTOADS
$webservice = $this->forward('App\Controller\WebserviceController::otoads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 395: // Solar BENL OTOADS
$webservice = $this->forward('App\Controller\WebserviceController::otoads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 394: // Solar UK Spotdif
$webservice = $this->forward('App\Controller\WebserviceController::spotdif', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 393: // Deuda ES Enley
$webservice = $this->forward('App\Controller\WebserviceController::enley', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 392: // DeudaFix ES DeudaFix
$webservice = $this->forward('App\Controller\WebserviceController::deudafix', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 391: // ZonnePannelen NL Innodora
$webservice = $this->forward('App\Controller\WebserviceController::innodora', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 390: // Paneles Solares HolaLuz
$webservice = $this->forward('App\Controller\WebserviceController::holaluz', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 389: // Paneles Solares ES
$webservice = $this->forward('App\Controller\WebserviceController::habitissimo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 387: // Maverick SolMedia Limited Solar UK
$webservice = $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 386: // Test Sellyourhouse
$webservice = $this->forward('App\Controller\WebserviceController::smhf', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 385: // Eltex Solar ES
$webservice = $this->forward('App\Controller\WebserviceController::eltexsolar', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 384: // Movagency Decesos
$webservice = $this->forward('App\Controller\WebserviceController::movadgency', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 383: // Dlulisa Zonnepanelen NL
$webservice = $this->forward('App\Controller\WebserviceController::dlulisa', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 382: // Dlulisa Zonnepanelen NL
$webservice = $this->forward('App\Controller\WebserviceController::dlulisa', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 381: // Maverick SolMedia Limited Solar UK
$webservice = $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 380: // Paneles Solares ES ExpertaSolar
$webservice = $this->forward('App\Controller\WebserviceController::expertasolar', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 378: // Test Sellyourhouse
$webservice = $this->forward('App\Controller\WebserviceController::smhf', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 377: // Panneaux Solaire Gasmobi
$webservice = $this->forward('App\Controller\WebserviceController::gasmobi', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 376: // Turbo Debt DebtUS
$webservice = $this->forward('App\Controller\WebserviceController::turbodebt', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 375: // SolarCorp Panneaux Solaire
$webservice = $this->forward('App\Controller\WebserviceController::solarcorp', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 374: // EngelEnergy Paneles Solares ES
$webservice = $this->forward('App\Controller\WebserviceController::engelenergy', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 373: // House Selling US Sell My House Fast LLC
$webservice = $this->forward('App\Controller\WebserviceController::smhf', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 372: // Rachat de Credit Devissima
$webservice = $this->forward('App\Controller\WebserviceController::devissima', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 370: // Odd Marketing Roofing US
$webservice = $this->forward('App\Controller\WebserviceController::oddmarketing', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 369: // Odd Marketing Roofing US
$webservice = $this->forward('App\Controller\WebserviceController::oddmarketing', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 368: // Odd Marketing Roofing US
$webservice = $this->forward('App\Controller\WebserviceController::oddmarketing', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 367: // Odd Marketing Windows US
$webservice = $this->forward('App\Controller\WebserviceController::oddmarketing', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 366: // MediaBrava Seguros ES
$webservice = $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 364: // Dlulisa Zonnepanelen NL
$webservice = $this->forward('App\Controller\WebserviceController::dlulisa', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 363: // MediaBrava Seguros ES
$webservice = $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 362: // MediaBrava Seguros ES
$webservice = $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 361: // MediaBrava Seguros ES
$webservice = $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 360: // MediaBrava Seguros ES
$webservice = $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 359: // MediaBrava Seguros ES
$webservice = $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 358: // MediaBrava Seguros ES
$webservice = $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 356: // Billy Roof Internal
$webservice = $this->forward('App\Controller\WebserviceController::billyexternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 355: // Billy Roof Internal
$webservice = $this->forward('App\Controller\WebserviceController::billy', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 354: //Bathroom US AdventumLLC
$webservice = $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 353: //Alarms US AdventumLLC
$webservice = $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 352: //Flooring US AdventumLLC
$webservice = $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 351: //Windows US AdventumLLC
$webservice = $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 350: //Solar US AdventumLLC
$webservice = $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 349: //Roof US AdventumLLC
$webservice = $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 346: //Offerte B.V Isolatie
$webservice = $this->forward('App\Controller\WebserviceController::offertebvnew', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 345: //InterDM B.V Hypotheek
$webservice = $this->forward('App\Controller\WebserviceController::interdmbv', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 344: //ExchangeFlo Roofing US
$webservice = $this->forward('App\Controller\WebserviceController::exchangeflo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 343: //ExchangeFlo Solar US
$webservice = $this->forward('App\Controller\WebserviceController::exchangeflo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 342: //MYS Zonnepanelen NL
$webservice = $this->forward('App\Controller\WebserviceController::mys', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 340: //SWN9 Zonnepanelen BENL
$webservice = $this->forward('App\Controller\WebserviceController::swingingmonkey', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
dd($webservice);
break;
case 338: //grocasa
$webservice = $this->forward('App\Controller\WebserviceController::grocasa', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 337: //Swinging Monkey Zonnepanelen
$webservice = $this->forward('App\Controller\WebserviceController::swingingmonkey', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 336: //EDM Windows
$webservice = $this->forward('App\Controller\WebserviceController::EDM', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
dd($webservice);
break;
case 335: //EDM Solar
$webservice = $this->forward('App\Controller\WebserviceController::EDM', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 334: //Zonnepanelen Spark Digital LTD
$webservice = $this->forward('App\Controller\WebserviceController::sparkdigital', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 333: //EDM Roofing
$webservice = $this->forward('App\Controller\WebserviceController::EDM', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 330: //Trafficon FR
$webservice = $this->forward('App\Controller\WebserviceController::trafficon', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 329: //Trafficon ES
$webservice = $this->forward('App\Controller\WebserviceController::trafficon', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 328: //Trafficon DE
$webservice = $this->forward('App\Controller\WebserviceController::trafficon', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 327: //Trafficon IT
$webservice = $this->forward('App\Controller\WebserviceController::trafficon', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 326: //UptownLeads Windows
$webservice = $this->forward('App\Controller\WebserviceController::uptownleads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 325: //UptownLeads Flooring
$webservice = $this->forward('App\Controller\WebserviceController::uptownleads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 324: //UptownLeads Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::uptownleads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 323: //UptownLeads Alarm
$webservice = $this->forward('App\Controller\WebserviceController::uptownleads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 322: //UptownLeads Roof
$webservice = $this->forward('App\Controller\WebserviceController::uptownleads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 321: //UptownLeads Solar
$webservice = $this->forward('App\Controller\WebserviceController::uptownleadssolar', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 320: //Drobu Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::drobu', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 319: //Drobu Premium Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::drobupremium', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 318: //Drobu Flooring
$webservice = $this->forward('App\Controller\WebserviceController::drobu', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 317: //Drobu Premium Flooring
$webservice = $this->forward('App\Controller\WebserviceController::drobupremium', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 316: //Drobu Windows
$webservice = $this->forward('App\Controller\WebserviceController::drobu', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 314: //Drobu Premium Windows
$webservice = $this->forward('App\Controller\WebserviceController::drobupremium', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 313: //Drobu Roofing
$webservice = $this->forward('App\Controller\WebserviceController::drobu', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 312: //Drobu Premium Roofing
$webservice = $this->forward('App\Controller\WebserviceController::drobupremium', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 311: //Drobu Solar
$webservice = $this->forward('App\Controller\WebserviceController::drobusolar', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 310: //Drobu Solar Premium
$webservice = $this->forward('App\Controller\WebserviceController::drobupremiumsolar', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 309: //Alpine Floor
$webservice = $this->forward('App\Controller\WebserviceController::alpine', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 306: // Windows Addaftech US
$webservice = $this->forward('App\Controller\WebserviceController::addaftech', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 305: // Paneles Solares ES Daicos
$webservice = $this->forward('App\Controller\WebserviceController::daicos', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 304: // ZonnePanelen
$webservice = $this->forward('App\Controller\WebserviceController::offertebvnew', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 303: // Alarms
$webservice = $this->forward('App\Controller\WebserviceController::remodelwell', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 302: // Paneles Solares España
$webservice = $this->forward('App\Controller\WebserviceController::mediaadgo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 298: // NL Zonnepanelen
$webservice = $this->forward('App\Controller\WebserviceController::yello', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 297: // TESTS
$webservice = $this->forward('App\Controller\WebServiceController::post_'.$campaign->getId(), array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 294: // US Roofing Acquire Crowd
$webservice = $this->forward('App\Controller\WebserviceController::acquirecrowd', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 293: // NL Zonnepanelen SunnyGreen
$webservice = $this->forward('App\Controller\WebserviceController::sunnygreen', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 292: // NL Zonnepanelen ABC Solar
$webservice = $this->forward('App\Controller\WebserviceController::abcsolar', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 291: // PANELES SOLARES SOLAR PROFIT ES
$webservice = $this->forward('App\Controller\WebserviceController::solarprofit', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 290: // NL Zonnepanelen Easydura
$webservice = $this->forward('App\Controller\WebserviceController::easydura', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 289: // Roofing US SBBNET
$webservice = $this->forward('App\Controller\WebserviceController::sbbnet', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 284: // Paneles Solares ES Digien
$webservice = $this->forward('App\Controller\WebserviceController::digien', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 282: // Mentormut Senior
$webservice = $this->forward('App\Controller\WebserviceController::clicklab', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 281: // Paneles Solares ES
$webservice = $this->forward('App\Controller\WebserviceController::clicklab', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 280: // Panneaux Solaire FR
$webservice = $this->forward('App\Controller\WebserviceController::clicklab', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 278: // Zonnepannelen NL Hilead
$webservice = $this->forward('App\Controller\WebserviceController::encompass', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 271: // Zonnepannelen NL Hilead
$webservice = $this->forward('App\Controller\WebserviceController::hilead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 270: // Zonnepannelen BENL OfferteBV
$webservice = $this->forward('App\Controller\WebserviceController::offertebvnew', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 269: // Roofing US LongHome
$webservice = $this->forward('App\Controller\WebserviceController::longhome', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 268: // Windows US SBBNET
$webservice = $this->forward('App\Controller\WebserviceController::sbbnet', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 267: // Octo Paneles Solares
$webservice = $this->forward('App\Controller\WebserviceController::octo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 263: // Assurance Voiture MeilleaurTaux
$webservice = $this->forward('App\Controller\WebserviceController::meilleaurtaux', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 262: // Alarm Vivint Email renter
$webservice = $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 261: // Alarm Vivint Email owner
$webservice = $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 260: // Alarm ADT Email renter
$webservice = $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 259: // Alarm ADT Email owner
$webservice = $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 258: // Lead Giant Windows Solar US
$webservice = $this->forward('App\Controller\WebserviceController::leadgiant', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 257: // Lead Giant Roofing Solar US
$webservice = $this->forward('App\Controller\WebserviceController::leadgiant', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 256: // Lead Giant Bathroom Solar US
$webservice = $this->forward('App\Controller\WebserviceController::leadgiant', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 255: // Alarms Solar US Vivint Nonemail renter
$webservice = $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 254: // Alarms Solar US Vivint Nonemail owner
$webservice = $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 253: // Alarms Solar US ADT Nonemail renter
$webservice = $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 252: // Alarms Solar US ADT Nonemail owner
$webservice = $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 251: // Bathroom Solar US
$webservice = $this->forward('App\Controller\WebserviceController::bluefire', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 250: // Roofing Solar US
$webservice = $this->forward('App\Controller\WebserviceController::bluefire', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 249: // Windows Solar US
$webservice = $this->forward('App\Controller\WebserviceController::bluefire', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 248: // Bathroom Home You US
$webservice = $this->forward('App\Controller\WebserviceController::homeyou', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 247: // Flooring Home You US
$webservice = $this->forward('App\Controller\WebserviceController::homeyou', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 246: // Roof Home You US
$webservice = $this->forward('App\Controller\WebserviceController::homeyou', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 245: // Windows DMS US
$webservice = $this->forward('App\Controller\WebserviceController::DMS', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 244: // LeadNovate Solar Panel
$webservice = $this->forward('App\Controller\WebserviceController::leadnovate', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 243: // Flooring Ever Connect US
$webservice = $this->forward('App\Controller\WebserviceController::everconnect', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 242: // Bathroom Ever Connect US
$webservice = $this->forward('App\Controller\WebserviceController::everconnect', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 241: // Roof Ever Connect US
$webservice = $this->forward('App\Controller\WebserviceController::everconnect', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 240: // Colossus Solar Panel
$webservice = $this->forward('App\Controller\WebserviceController::newcolossus', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 239: // /TEST PANELES SOLARES
$webservice = $this->forward('App\Controller\WebserviceController::mediaadgo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 238: // Windows Ever Connect US
$webservice = $this->forward('App\Controller\WebserviceController::everconnect', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 237: // BlueFire Solar US
$webservice = $this->forward('App\Controller\WebserviceController::bluefire', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 236: // Solar Momentum US
$webservice = $this->forward('App\Controller\WebserviceController::momentum', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 235: // Bathroom Click Dealer US
$webservice = $this->forward('App\Controller\WebserviceController::clickdealer', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 234: // Windows Click Dealer US
$webservice = $this->forward('App\Controller\WebserviceController::clickdealer', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 233: // Roofing Click Dealer US
$webservice = $this->forward('App\Controller\WebserviceController::clickdealer', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 232: // Roofing Click Dealer US
$webservice = $this->forward('App\Controller\WebserviceController::clickdealer', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 230: // Solar Fluent US
$webservice = $this->forward('App\Controller\WebserviceController::fluentsolar', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 229: //LinkEtLead PV12
$webservice = $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 228: // Windows Home You US
$webservice = $this->forward('App\Controller\WebserviceController::homeyou', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 227: // Windows Addaftech US
$webservice = $this->forward('App\Controller\WebserviceController::addaftech', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 226: // Roofing Addaftech US
$webservice = $this->forward('App\Controller\WebserviceController::addaftech', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 225: // Bathroom Addaftech US
$webservice = $this->forward('App\Controller\WebserviceController::addaftech', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 224: // Solar Addaftech US
$webservice = $this->forward('App\Controller\WebserviceController::addaftech', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 223: // Roof DMS US
$webservice = $this->forward('App\Controller\WebserviceController::DMS', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 222: // Roof DMS US
$webservice = $this->forward('App\Controller\WebserviceController::DMS', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 221: //LinkEtLead PV14
$webservice = $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 220: // Blue ink Alarms
$webservice = $this->forward('App\Controller\WebserviceController::blueinkexternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 219: // Blue ink Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::blueinkexternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 218: // Blue ink Flooring
$webservice = $this->forward('App\Controller\WebserviceController::blueinkexternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 217: // Blue ink Roofing
$webservice = $this->forward('App\Controller\WebserviceController::blueinkexternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 216: // Blue ink Solar Panels
$webservice = $this->forward('App\Controller\WebserviceController::blueinkexternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 215: // Bathroom Presidio Interactive Corp. US
$webservice = $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 214: // Windows Presidio Interactive Corp. US
$webservice = $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 213: // Flooring Presidio Interactive Corp. US
$webservice = $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 212: // Roofing Presidio Interactive Corp. US
$webservice = $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 211: //Windows US Encompass
$webservice = $this->forward('App\Controller\WebserviceController::encompass', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 210: //Bathroom US Encompass
$webservice = $this->forward('App\Controller\WebserviceController::encompass', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 209: //Roof US Encompass
$webservice = $this->forward('App\Controller\WebserviceController::encompass', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 208: //Solar US Encompass
$webservice = $this->forward('App\Controller\WebserviceController::encompass', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 207: // Kozijnen Offertevergelijker
$webservice = $this->forward('App\Controller\WebserviceController::offertevergelijker', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 206: // TrapRenovatie Offertevergelijker
$webservice = $this->forward('App\Controller\WebserviceController::offertevergelijker', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 205: // Solar DMS US
$webservice = $this->forward('App\Controller\WebserviceController::DMS', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 204: // Alarms Presidio Interactive Corp. US
$webservice = $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 203: // Solar Panel Presidio Interactive Corp. US
$webservice = $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 201: // CostaBlanca Solar
$webservice = $this->forward('App\Controller\WebserviceController::costablanca', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 200: // Miligroup Security
$webservice = $this->forward('App\Controller\WebserviceController::miligroup', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 199: // Miligroup Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::miligroup', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 198: // Finetwork ES
/* if(str_contains($lead->getEmail(), '@test.com') == true){
$webservice = array(
"response" => "test",
"wscall" => "none",
"check" => "1",
"price" => "0",
);
$webservice = json_encode($webservice);
}else{*/
$webservice = $this->forward('App\Controller\WebserviceController::finetwork', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
/* }*/
break;
case 197: // Billy Windows External
$webservice = $this->forward('App\Controller\WebserviceController::billyexternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 196: // Billy Windows Internal
$webservice = $this->forward('App\Controller\WebserviceController::billy', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 195: // Billy Flooring External
$webservice = $this->forward('App\Controller\WebserviceController::billyexternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 194: // Billy Flooring Internal
$webservice = $this->forward('App\Controller\WebserviceController::billy', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 193: // Billy Alarm External
$webservice = $this->forward('App\Controller\WebserviceController::billyexternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 192: // Billy Alarm Internal
$webservice = $this->forward('App\Controller\WebserviceController::billy', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 191: // Billy Solar External
$webservice = $this->forward('App\Controller\WebserviceController::billyexternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 190: // Billy Solar
$webservice = $this->forward('App\Controller\WebserviceController::billy', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 189: // RemodelWell Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::remodelwell', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 188: // RemodelWell Windows
$webservice = $this->forward('App\Controller\WebserviceController::remodelwell', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 187: // RemodelWell Roof
$webservice = $this->forward('App\Controller\WebserviceController::remodelwell', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 186: // RemodelWell Solar
$webservice = $this->forward('App\Controller\WebserviceController::YAC', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 185: // RemodelWell Solar
$webservice = $this->forward('App\Controller\WebserviceController::bobex', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 184: // RemodelWell Solar
$webservice = $this->forward('App\Controller\WebserviceController::remodelwell', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 183: // Miligroup Windows
$webservice = $this->forward('App\Controller\WebserviceController::miligroup', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 182: // Miligroup Flooring
$webservice = $this->forward('App\Controller\WebserviceController::miligroup', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 181: //LinkEtLead PAC14
$webservice = $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 180: //Confluent Panneaux Solaire
$webservice = $this->forward('App\Controller\WebserviceController::confluent', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 179: //Confluent Panneaux Solaire
$webservice = $this->forward('App\Controller\WebserviceController::confluent', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 178: //Digital in perf Panneaux Solaire
$webservice = $this->forward('App\Controller\WebserviceController::dedeco', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 177: //Digital in perf Panneaux Solaire
$webservice = $this->forward('App\Controller\WebserviceController::digitalinperf', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 176: //Digital in perf Pac Chauffage
$webservice = $this->forward('App\Controller\WebserviceController::digitalinperf', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 174: // Miligroup Roof
$webservice = $this->forward('App\Controller\WebserviceController::dedeco', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 173: // Miligroup Roof
$webservice = $this->forward('App\Controller\WebserviceController::miligroup', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 172: // Bobex Zonnepanelen BENL
$webservice = $this->forward('App\Controller\WebserviceController::bobex', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 171: //Alarms Blue Ink
$webservice = $this->forward('App\Controller\WebserviceController::YAC', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 170: //Alarms Blue Ink
$webservice = $this->forward('App\Controller\WebserviceController::blueinkinternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 169: //Alarms Allied Digital Media
$webservice = $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 168: //Vivint Alarms
$webservice = $this->forward('App\Controller\WebserviceController::vivint', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 167: //Modernize Alarms
$webservice = $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 166:// Lets Make A Lead Alarms
$webservice = $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 165: //LinkEtLead PV11 panneaux solaire
$webservice = $this->forward('App\Controller\WebserviceController::convergedirect', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 164: //LinkEtLead PV11 panneaux solaire
$webservice = $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 163: //Roofing Allied Digital Media
$webservice = $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 162: //Bathroom Allied Digital Media
$webservice = $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 161: //Flooring Allied Digital Media
$webservice = $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 160: //Windows Allied Digital Media
$webservice = $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 159: //Windows Allied Digital Media
$webservice = $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 158: //Bathroom LeadVision
$webservice = $this->forward('App\Controller\WebserviceController::leadvision', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 157: //Solar LeadVision
$webservice = $this->forward('App\Controller\WebserviceController::leadvision', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 156: //LinkEtLead PV10 panneaux solaire
$webservice = $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 155: //ADT Solar
$webservice = $this->forward('App\Controller\WebserviceController::ADT', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 154: //Bluewings Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::bluewings', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 153: //Bluewings Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::bluewings', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 152: //Bluewings Roof
$webservice = $this->forward('App\Controller\WebserviceController::bluewings', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 151: //Bluewings Windows
$webservice = $this->forward('App\Controller\WebserviceController::bluewings', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 150: //Bluewings Solar
$webservice = $this->forward('App\Controller\WebserviceController::bluewings', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 149: //LinkEtLead
$webservice = $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 148: //Alpine Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::alpine', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 147: //Alpine Roofing
$webservice = $this->forward('App\Controller\WebserviceController::alpine', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 146: //Alpine Windows
$webservice = $this->forward('App\Controller\WebserviceController::alpine', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 144: //Pointer Flooring
$webservice = $this->forward('App\Controller\WebserviceController::alpine', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 143: //Pointer Flooring
$webservice = $this->forward('App\Controller\WebserviceController::pointer', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 142: //IntelHouseMarketing Flooring
$webservice = $this->forward('App\Controller\WebserviceController::intelhouse', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 141: //IntelHouseMarketing Windows
$webservice = $this->forward('App\Controller\WebserviceController::intelhouse', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 140: //IntelHouseMarketing Bath
$webservice = $this->forward('App\Controller\WebserviceController::intelhouse', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 139: //IntelHouseMarketing Roof
$webservice = $this->forward('App\Controller\WebserviceController::intelhouse', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 138: //IntelHouseMarketing Solar
$webservice = $this->forward('App\Controller\WebserviceController::intelhouse', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 137: //Modernize Solar
$webservice = $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 136: //Pointer Windows US
$webservice = $this->forward('App\Controller\WebserviceController::pointer', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 135: //Invexperto
$webservice = $this->forward('App\Controller\WebserviceController::DBInvest', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 134: //Pointer Roof US
$webservice = $this->forward('App\Controller\WebserviceController::pointer', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 133: //Pointer Bathroom US
$webservice = $this->forward('App\Controller\WebserviceController::pointer', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 132: //Pointer Solar US
$webservice = $this->forward('App\Controller\WebserviceController::pointer', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 131: //Turtle Bath US
$webservice = $this->forward('App\Controller\WebserviceController::offertebv', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 123: //Turtle Bath US
$webservice = $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 122: //Turtle Bath US
$webservice = $this->forward('App\Controller\WebserviceController::turtleleads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 121: //Turtle Windows US
$webservice = $this->forward('App\Controller\WebserviceController::turtleleads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 120: //Turtle Floor US
$webservice = $this->forward('App\Controller\WebserviceController::turtleleads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 119: //Turtle Roof US
$webservice = $this->forward('App\Controller\WebserviceController::turtleleads', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 118: //Turtle Solar US
$webservice = $this->forward('App\Controller\WebserviceController::turtleleadssolar', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 117: //Cactus
$webservice = $this->forward('App\Controller\WebserviceController::cactus', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 116:// Blue ink Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::blueinkinternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 115:// Modernize Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 114:// Lets Make A Lead Bathroom
$webservice = $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 113:// Top10 Ping/Post Roofing
$webservice = $this->forward('App\Controller\WebserviceController::top10ping', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 112:// LINKETLEAD PAC
$webservice = $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 111:// RGR MARKETING ROOFING
$webservice = $this->forward('App\Controller\WebserviceController::RGR', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 109:// RGR MARKETING ROOFING
$webservice = $this->forward('App\Controller\WebserviceController::RGR', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 110:// RGR MARKETING ROOFING
$webservice = $this->forward('App\Controller\WebserviceController::RGR', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 106:
case 103:
case 102:
case 108: //
$webservice = $this->forward('App\Controller\WebserviceController::YAC', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 107: //
$webservice = $this->forward('App\Controller\WebserviceController::cactus', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 99:
case 105: // Airo Windows US
$webservice = $this->forward('App\Controller\WebserviceController::airo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 101: // Top10 Windows US
$webservice = $this->forward('App\Controller\WebserviceController::TOP10', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 100: // Modernize Windows US
$webservice = $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 98: // Letsmakealead Windows US
$webservice = $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 97: // Blue ink Floor US
$webservice = $this->forward('App\Controller\WebserviceController::airo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 96: // Blue ink Floor US
$webservice = $this->forward('App\Controller\WebserviceController::blueinkinternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 95: // Modernize Flooring US
$webservice = $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 94: // Airo Roof US
$webservice = $this->forward('App\Controller\WebserviceController::airo', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 93: // Letsmakealead Roof US
$webservice = $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 91: // Letsmakealead Floor US
$webservice = $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 90: // EMPIRE FLOORING FLOOR US
$webservice = $this->forward('App\Controller\WebserviceController::empireflooring', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 89: // BLUE INK ROOFING US
$webservice = $this->forward('App\Controller\WebserviceController::blueinkinternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 88: // Modernize Roofing US
$webservice = $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 87: // TOP 10 Roof US
$webservice = $this->forward('App\Controller\WebserviceController::TOP10', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 85: // novaxpress SOLAR PANEL
$webservice = $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 84: // LETSMAKELEAD SOLAR PANEL
$webservice = $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 83: // TOP10 MARKETING SOLAR PANEL
$webservice = $this->forward('App\Controller\WebserviceController::TOP10', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 82: // RGR MARKETING SOLAR PANEL
$webservice = $this->forward('App\Controller\WebserviceController::RGR', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 78:
case 79:
case 80:
case 81: // BlueMedia CRYPTO BE
$webservice = $this->forward('App\Controller\WebserviceController::bluemedia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 77: // SAMARA ENERGIA SL PANELES SOLARES
$webservice = $this->forward('App\Controller\WebserviceController::samara', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 76: // Sunrun Solas Paneles
$webservice = $this->forward('App\Controller\WebserviceController::sunrun', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 75: // Colossus Solas Paneles
$webservice = $this->forward('App\Controller\WebserviceController::colossus', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 74: // Blue ink Solas Paneles
$webservice = $this->forward('App\Controller\WebserviceController::blueinkinternal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 73: // SBBNET Solas Paneles
$webservice = $this->forward('App\Controller\WebserviceController::SBBNET', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 72: // SDM Solas Paneles
$webservice = $this->forward('App\Controller\WebserviceController::SDM', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 71: // Pac Chauffage LinketLead
$webservice = $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 70: // Mobipium Solar Paneles
$webservice = $this->forward('App\Controller\WebserviceController::mobipium', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 68: // PARKING Bewowin
$webservice = $this->forward('App\Controller\WebserviceController::betowin', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 67: // CPF Betowin
$webservice = $this->forward('App\Controller\WebserviceController::betowin', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 66: // Panneaux LinkEtLead
$webservice = $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 65: // Panneaux LinkEtLead
$webservice = $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 64: // Internovous Forex NL
$webservice = $this->forward('App\Controller\WebserviceController::internovus', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 63: // SOI HolaLuz
$webservice = $this->forward('App\Controller\WebserviceController::horaluz', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 62: // WEENDEAL, Mutuelle Seniors
$webservice = $this->forward('App\Controller\WebserviceController::weendal', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 61: // CLIDOM-SOLAR, S.L. Paneles Solares Spain
$webservice = $this->forward('App\Controller\WebserviceController::horaluz', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 60: // Novaexpress Mutuelle Seniors
$webservice = $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 59: // PAC Chauffage
$webservice = $this->forward('App\Controller\WebserviceController::spin8', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 58: // Courtalys
$webservice = $this->forward('App\Controller\WebserviceController::blackandwhite', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 57: // Courtalys
$webservice = $this->forward('App\Controller\WebserviceController::courtalys', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 55: // black and white investissment
$webservice = $this->forward('App\Controller\WebserviceController::blackandwhite', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 54: // black and white crypto fr
$webservice = $this->forward('App\Controller\WebserviceController::blackandwhite', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 52: // Novaexpress PAC chauffage
$webservice = $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 51: // CBM Adoucisseur d'eau
$webservice = $this->forward('App\Controller\WebserviceController::cbm', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 50: // Forex FR Mythos
$webservice = $this->forward('App\Controller\WebserviceController::mythos', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 49: // Novaexpress Adoucisseur d'eau
$webservice = $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 48: // Forex NL Mythos
$webservice = $this->forward('App\Controller\WebserviceController::mythos', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 47: // Forex IT Mythos
$webservice = $this->forward('App\Controller\WebserviceController::mythos', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 45: // Forex IT Internovus
$webservice = $this->forward('App\Controller\WebserviceController::internovus', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 44: // Amazon Invest BENL
$webservice = $this->forward('App\Controller\WebserviceController::maisontraffic', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 43: // Amazon Invest NL
$webservice = $this->forward('App\Controller\WebserviceController::maisontraffic', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 42: // Amazon Invest IT
$webservice = $this->forward('App\Controller\WebserviceController::maisontraffic', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 40: // Bobex Zonnepanelen BENL
$webservice = $this->forward('App\Controller\WebserviceController::bobex', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 36: // Atlas Power
$webservice = $this->forward('App\Controller\WebserviceController::atlaspower', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 35: // Solar Concept
$webservice = $this->forward('App\Controller\WebserviceController::solarconcept', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 34: // BewustCollectief
$webservice = $this->forward('App\Controller\WebserviceController::bewustcollectief', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 30:// Panneaux Solaire
$webservice = $this->forward('App\Controller\WebserviceController::spin8', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 27: // CPF Spin8
$webservice = $this->forward('App\Controller\WebserviceController::spin8', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 23: // Bobex Isolatie
$webservice = $this->forward('App\Controller\WebserviceController::bobex', array('data' => $fields, 'campaign' => 23))->getContent();
break;
case 21: // Bobex Zonnepanelen NL
$webservice = $this->forward('App\Controller\WebserviceController::bobex', array('data' => $fields, 'campaign' => 21))->getContent();
break;
case 20: // Get up media panneaux solaires
$webservice = $this->forward('App\Controller\WebserviceController::getupmedia', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 19: // Novaexpress panneaux solaires
$webservice = $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields, 'campaign' => 19))->getContent();
break;
case 17: // Novaexpress Livret
$webservice = $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields, 'campaign' => 17))->getContent();
break;
case 26: // Novaexpress CPF
$webservice = $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
case 14: // Offerte BV Isolatie
$webservice = $this->forward('App\Controller\WebserviceController::offertebv', array('data' => $fields, 'campaign' => 14))->getContent();
break;
case 13: // Offerte BV Zonnepanelen
$webservice = $this->forward('App\Controller\WebserviceController::offertebv', array('data' => $fields, 'campaign' => 13))->getContent();
break;
case 11: // Offertevergelijker Zonnepanelen
$webservice = $this->forward('App\Controller\WebserviceController::offertevergelijker', array('data' => $fields, 'campaign' => 11))->getContent();
break;
case 16: // Offertevergelijker Isolatie
$webservice = $this->forward('App\Controller\WebserviceController::offertevergelijker', array('data' => $fields, 'campaign' => 16))->getContent();
break;
case 15: // Datafanatics Isolatie
$webservice = $this->forward('App\Controller\WebserviceController::datafanatics', array('data' => $fields, 'campaign' => 15))->getContent();
break;
case 7: // Datafanatics Zonnepanelen
$webservice = $this->forward('App\Controller\WebserviceController::datafanatics', array('data' => $fields, 'campaign' => 7))->getContent();
break;
case 9: // Consumind Energie
$webservice = $this->forward('App\Controller\WebserviceController::consumind', array('data' => $fields))->getContent();
break;
case 4: // Vente-Unique PL
$webservice = $this->forward('App\Controller\WebserviceController::venteuniquepl', array('data' => $fields))->getContent();
break;
case 5: // Vente-Unique PT
$webservice = $this->forward('App\Controller\WebserviceController::venteuniquept', array('data' => $fields))->getContent();
break;
case 6: // Vente-Unique BEFR
$webservice = $this->forward('App\Controller\WebserviceController::venteuniquebefr', array('data' => $fields))->getContent();
break;
case 3: // Test
$webservice = $this->forward('App\Controller\WebserviceController::loudingads2', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
break;
}
$webservice = json_decode($webservice);
if (!isset($webservice->check)) {
$arraycheck[$campaign->getId()]["check"]=0;
$arraycheck[$campaign->getId()]["filter"]=1;
$response = 2;
if ($campaign->getEmailNotification()){
$to = 'lennard@loudingads.com';
$subject = 'Error in campaign '. $campaign->getId();
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
if (!$webservice){
$webservice = "Uncaught Webservice";
}
$this->emailService->sendEmail($to,"lennard@loudingads.com", $subject, $webservice, $headers);
}
} else {
if ($webservice->check == 1) { // Lead suceessfully send to the customer and accepted
$arraycheck[$campaign->getId()]["check"]=1;
$arraycheck[$campaign->getId()]["filter"]=1;
//$result['validcampaign'] = true;
// $result['validcustomer'] = true;
if ($campaign->getVariablePrice() == 1){
if (isset($webservice->price)){
$result['revenue'] = $result['revenue'] + $webservice->price;
}else{
$result['revenue'] = $result['revenue'] + $campaign->getPrice();
}
}else{
$result['revenue'] = $result['revenue'] + $campaign->getPrice();
}
$result['sold'] = $result['sold'] + 1;
if(str_contains($lead->getEmail(), '@loudingest.com') == false){
$campaign->setGross($campaign->getGross() + 1);
$campaign->setValid($campaign->getValid() + 1);
if ($campaign->getVariablePrice() == 1){
if (isset($webservice->price)){
$campaign->setRevenue($campaign->getRevenue() + $webservice->price);
}else{
$campaign->setRevenue($campaign->getRevenue() + $campaign->getPrice());
}
}else{
$campaign->setRevenue($campaign->getRevenue() + $campaign->getPrice());
}
}
$response = 1;
} else { // Lead rejected by the customer
$arraycheck[$campaign->getId()]['check'] = 0;
$arraycheck[$campaign->getId()]['filter'] = 1;
$campaign->setGross($campaign->getGross() + 1);
$campaign->setInvalid($campaign->getInvalid() + 1);
$response = 0;
}
$em->persist($campaign);
$em->flush();
// Register the call into wslog
$wslog = new Wslog();
$wslog->setCampaign($campaign);
$wslog->setLead($lead);
$wslog->setResponse($webservice->check);
//$wslog->setType($ws->getMethod());
$wslog->setFeedback($webservice->response);
$wslog->setTimestamp(new \Datetime('Europe/Madrid'));
$wslog->setWscall(json_encode($webservice->wscall, JSON_UNESCAPED_SLASHES));
$em->persist($wslog);
$em->flush();
if ($campaign->getEmailNotification()){
if(str_contains($lead->getEmail(), '@loudingest.com') == false){
$this->campaignService->verifyAndSendEmail($lead,$campaign);
}
}
}
} else { // If campaign as validation manual
$result['revenue'] = $result['revenue'] + $campaign->getPrice();
$result['sold'] = $result['sold'] + 1;
//$result['validcampaign'] = true;
$arraycheck[$campaign->getId()]['filter'] = 1;
//$result['validcustomer'] = true;
$arraycheck[$campaign->getId()]['check'] = 1;
$response = 1; // valid lead sent
}
// Set leadcampaign
$leadcampaign = new Leadcampaign();
$leadcampaign->setLead($lead);
$leadcampaign->setCampaign($campaign);
if (isset($webservice->buyerid) && $webservice->buyerid != null){
$leadcampaign->setBuyerid($webservice->buyerid);
}
if (isset($wslog)) {
$leadcampaign->setWs($wslog);
$leadcampaign->setReason('webservice');
if ($response == 1) {
$lc_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // valid
if (str_contains($lead->getEmail(), '@loudingest.com') == true){
$lc_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(18);
} else {
$campaign->setCappingReach($campaign->getCappingReach() + 1);
$campaign->setDailyreach($campaign->getDailyreach() + 1);
$campaign->setMonthlyreach($campaign->getMonthlyreach() + 1);
$campaign->setWeeklyreach($campaign->getWeeklyreach() + 1);
if ($campaign->getDailycap() == $campaign->getDailyreach() && $campaign->getDailycap() != 0){
$campaignstatus = $this->getDoctrine()->getRepository(Status::class)->findOneById(10);
$campaign->setStatus($campaignstatus);
}
if ($campaign->getWeeklycapping() == $campaign->getWeeklyreach() && $campaign->getWeeklycapping() != 0){
$campaignstatus = $this->getDoctrine()->getRepository(Status::class)->findOneById(13);
$campaign->setStatus($campaignstatus);
}
if ($campaign->getMonthlycap() == $campaign->getMonthlyreach() && $campaign->getMonthlycap() != 0){
$campaignstatus = $this->getDoctrine()->getRepository(Status::class)->findOneById(11);
$campaign->setStatus($campaignstatus);
}
if ($campaign->getCapping() == $campaign->getCappingReach() && ($campaign->getCapping() != 0 && $campaign->getCapping() != null)){
$campaignstatus = $this->getDoctrine()->getRepository(Status::class)->findOneById(12);
$campaign->setStatus($campaignstatus);
$campaign->setCappingReach(0);
}
}
$leadcampaign->setCampaign($campaign);
if(str_contains($lead->getEmail(), '@loudingest.com') == false) {
if ($campaign->getVariablePrice() == 1) {
if (isset($webservice->price)) {
$leadcampaign->setRevenue($webservice->price);
} else {
$leadcampaign->setRevenue($campaign->getPrice());
}
} else {
$leadcampaign->setRevenue($campaign->getPrice());
}
}
$leadcampaign->setStatus($lc_status);
$leadcampaign->setValidationdate(new \Datetime('Europe/Madrid'));
} else {
$lc_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(3); // invalid
$leadcampaign->setStatus($lc_status);
$leadcampaign->setValidationdate(new \Datetime('Europe/Madrid'));
}
} else { // the Campaign has no web service
$lc_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // active
$leadcampaign->setStatus($lc_status);
if (str_contains($lead->getEmail(), '@loudingest.com') != true){
$campaign->setCappingReach($campaign->getCappingReach() + 1);
$campaign->setDailyreach($campaign->getDailyreach() + 1);
$campaign->setMonthlyreach($campaign->getMonthlyreach() + 1);
$campaign->setWeeklyreach($campaign->getWeeklyreach() + 1);
if ($campaign->getDailycap() == $campaign->getDailyreach() && $campaign->getDailycap() != 0){
$campaignstatus = $this->getDoctrine()->getRepository(Status::class)->findOneById(10);
$campaign->setStatus($campaignstatus);
}
if ($campaign->getWeeklycapping() == $campaign->getWeeklyreach() && $campaign->getWeeklycapping() != 0){
$campaignstatus = $this->getDoctrine()->getRepository(Status::class)->findOneById(13);
$campaign->setStatus($campaignstatus);
}
if ($campaign->getMonthlycap() == $campaign->getMonthlyreach() && $campaign->getMonthlycap() != 0){
$campaignstatus = $this->getDoctrine()->getRepository(Status::class)->findOneById(11);
$campaign->setStatus($campaignstatus);
}
if ($campaign->getCapping() == $campaign->getCappingReach() && ($campaign->getCapping() != 0 && $campaign->getCapping() != null)){
$campaignstatus = $this->getDoctrine()->getRepository(Status::class)->findOneById(12);
$campaign->setStatus($campaignstatus);
$campaign->setCappingReach(0);
}
}
}
$leadcampaign->setCurrency($campaign->getCurrency());
$leadcampaign->setRegistrationdate(new \Datetime('Europe/Madrid'));
$em->persist($leadcampaign);
$em->flush();
}
} else { // filter campaign not passed
$arraycheck[$campaign->getId()]['filter'] = 0;
$arraycheck[$campaign->getId()]['check'] = 0;
}
if($response == 1) { // Customer accepted the lead
$c++;
}
if($this->testlead !== true || $this->testwebservice !== true) { // exclusivity only for test
//if($this->testlead !== true || $this->testwebservice !== true) { // don't apply exclusivity for test: the lead is sent to all the campaigns in test status
//if($testlead !== true && $testwebservice !== true) { // don't apply exclusivity for test: the lead is sent to all the campaigns in test status
if($c > $exclusivity) { // already reach the maximum number of lead to share
break;
}
}
}
// Set up the response array values
if(isset($arraycheck)){
$checkOne = array_filter($arraycheck, function ($element) {
return isset($element['check']) && $element['check'] === 1;
});
if (!empty($checkOne)) {
$result['validcustomer'] = true;
}else{
$result['validcustomer'] = false;
}
$checkTwo = array_filter($arraycheck, function ($element) {
return isset($element['filter']) && $element['filter'] === 1;
});
if (!empty($checkTwo)) {
$result['validcampaign'] = true;
}else{
$result['validcampaign'] = false;
}
}
return $result;
}
public function leadfield($fields, $data, $lead)
{
foreach ($fields as $field) {
$fieldname = $field->getName();
if (isset($data[$fieldname])) {
$leadfield = $this->insertleadfield($lead, $field, $data[$fieldname]);
}
}
return 1;
}
public function checkfilter($lead) { // Check if lead passes project filters
$active = $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
$project = $lead->getProject();
// Get all Filtergroup for this project
$filtersgroup = $this->getDoctrine()->getRepository(Filtergroup::class)->findBy(array(
'project' => $project,
'status' => $active
)
);
if (count($filtersgroup) > 0) { // check if there are any Filtergroup active
foreach ($filtersgroup as $filtergroup) {
$check = array();
$i = 0;
foreach ($filtergroup->getFilters() as $filter) { // Get all Filters from Filtergroup
$field = $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(array(
'lead' => $lead,
'field' => $filter->getField()
)
);
if($field !== null) {
$value = $field->getValue();
} else {
$value = null;
}
/*if ($field == null) {
return false;
} else {
$value = $field->getValue();
}*/
$filteroperator = $filter->getOperator()->getId();
$filtervalue = $filter->getValue();
$check[$i] = 0; // Condition false by default
//switch
if ($filteroperator == 1) { // equal
if ($value == $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 2) { // not equal
if ($value !== $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 3) { // contains
if (strpos($value, $filtervalue) !== false) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 4) { // not contains
if (!strpos($value, $filtervalue) !== false) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 5) { // =
if (is_numeric($value) && $value == $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 6) { // !=
if (is_numeric($value) && $value !== $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 7) { // >
if ($value > $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 8) { // >=
if ($value >= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 9) { // <
if ($value < $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 10) { // <=
if ($value <= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 11) { // = - date
if ($value == $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 12) { // != - date
if ($value !== $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 13) { // > - date
if ($value > $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 14) { // >= - date
if ($value >= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 15) { // < - date
if ($value < $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 16) { // <= - date
if ($value <= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 17) { // older than - date
$filtervalue = strtotime('- ' . $filtervalue . ' year');
$value = strtotime($value);
if ($value <= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 18) { // younger than - date
$filtervalue = strtotime('- ' . $filtervalue . ' year');
$value = strtotime($value);
if ($value >= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 19) { // starts with - string - case insensitive
if (str_starts_with(strtolower($value), strtolower($filtervalue)) !== false) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 20) { // ends with - string
if (str_ends_with(strtolower($value), strtolower($filtervalue)) !== false) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 21) { // hour before than - datetime
$value = substr($value,11,2);
if ($value < $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 22) { // hour later than - datetime
$value = substr($value,11,2);
if ($value >= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 23 || $filteroperator == 29) { // day of the week equal
$filtervalue = strtolower($filtervalue);
if ($filtervalue == strtolower(date('l')) || $filtervalue == strtolower(date('D'))) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 24 || $filteroperator == 30) { // day of the week different
$filtervalue = strtolower($filtervalue);
if ($filtervalue != strtolower(date('l')) && $filtervalue != strtolower(date('D'))) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 27) { // is empty
if($value == '' || $value == null) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 28) { // is not empty
if($value !== '' && $value !== null) {
$check[$i] = true;
} else {
$check[$i] = false;
}
}
$i++;
}
$boolean = $filtergroup->getBoolean();
if ($boolean == 0) { // all check must be true
if (in_array(false, $check)) {
$filtercheck = false;
} else {
$filtercheck = true;
}
} elseif ($boolean == 1) { // at least one check must be true
if (in_array(true, $check)) {
$filtercheck = true;
} else {
$filtercheck = false;
}
} elseif ($boolean == 2) { // all check must be false
if (in_array(true, $check)) {
$filtercheck = false;
} else {
$filtercheck = true;
}
}
try {
$report = new ProjectFilterLog();
$report->setLead($lead);
$report->setFiltergroup($filtergroup);
$report->setResult($filtercheck);
$report->setDate(time());
$em = $this->getDoctrine()->getManager();
$em->persist($report);
$em->flush();
}catch(\Exception $e){
}
if ($filtercheck == false) { // If only one filtergroup is false the loop blocks and return false
return $filtercheck;
}
}
} else { // No Filtergroup active
$filtercheck = true;
}
return $filtercheck;
}
public function checkcampaignfilter($lead, $campaign)
{
try {
$active = $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
$filtersgroup = $this->getDoctrine()->getRepository(Filtercampaigngroup::class)->findBy(array(
'campaign' => $campaign,
'status' => $active
)
);
$project = $lead->getProject();
if (count($filtersgroup) > 0) {
foreach ($filtersgroup as $fg) {
$check = array();
$i = 0;
foreach ($fg->getFilters() as $filter) {
$fieldcampaign = $filter->getFieldcampaign();
$repository = $this->getDoctrine()->getRepository(Field::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->andWhere(':fieldcampaign MEMBER OF c.fieldcampaigns');
$query->setParameter('fieldcampaign', $fieldcampaign->getId());
$query->andWhere('c.project = :project');
$query->setParameter('project', $project->getId());
$query = $query->getQuery();
$field = $query->getResult();
$value = $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(array(
'lead' => $lead,
'field' => $field[0]
)
);
if ($value == null) {
$report = new Campaignfilterlog();
$report->setLead($lead);
$report->setFiltergroup($fg);
$report->setResult(false);
$report->setDate(time());
$em = $this->getDoctrine()->getManager();
$em->persist($report);
$em->flush();
return false;
} else {
$value = $value->getValue();
}
$filteroperator = $filter->getOperator()->getId();
$filtervalue = $filter->getValue();
$check[$i] = 0; // Condition false by default
//Better to use a switch?
if ($filteroperator == 1) { // equal - string
if (strtolower($value) == strtolower($filtervalue)) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 2) { // not equal - string
if (strtolower($value) !== strtolower($filtervalue)) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 3) { // contains - string
if (strpos($value, $filtervalue) !== false) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 4) { // not contains - string
if (!strpos($value, $filtervalue) !== false) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 19) { // starts with - string
$value = str_replace(' ','',$value); // replace white spaces
if (str_starts_with(strtolower($value), strtolower($filtervalue)) !== false) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 20) { // ends with - string
$value = str_replace(' ','',$value); // replace white spaces
if (str_ends_with(strtolower($value), strtolower($filtervalue)) !== false) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 5) { // = - number
if (is_numeric($value) && $value == $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 6) { // != - number
if (is_numeric($value) && $value !== $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 7) { // > - number
if ($value > $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 8) { // >= - number
if ($value >= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 9) { // < - number
if ($value < $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 10) { // <= - number
if ($value <= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 11) { // = - date
if ($value == $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 12) { // != - date
if ($value !== $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 13) { // > - date
if ($value > $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 14) { // >= - date
if ($value >= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 15) { // < - date
if ($value < $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 16) { // <= - date
if ($value <= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 17) { // older than - date
$filtervalue = strtotime('- ' . $filtervalue . ' year');
$value = strtotime($value);
;
if ($value <= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
} elseif ($filteroperator == 18) { // younger than - date
$filtervalue = strtotime('- ' . $filtervalue . ' year');
$value = strtotime($value);
if ($value >= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
}
elseif ($filteroperator == 21) { // hour before than - datetime
$value = substr($value,11,2);
if ($value < $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
}
elseif ($filteroperator == 22) { // hour later than - datetime
$value = substr($value,11,2);
if ($value >= $filtervalue) {
$check[$i] = true;
} else {
$check[$i] = false;
}
}
elseif ($filteroperator == 23 || $filteroperator == 29) { // day of the week equal
$filtervalue = strtolower($filtervalue);
if ($filtervalue == strtolower(date('l')) || $filtervalue == strtolower(date('D'))) {
$check[$i] = true;
} else {
$check[$i] = false;
}
}
elseif ($filteroperator == 24 || $filteroperator == 30) { // day of the week different
date_default_timezone_set("Europe/Madrid");
$filtervalue = strtolower($filtervalue);
if ($filtervalue !== strtolower(date('l')) && $filtervalue !== strtolower(date('D'))) {
$check[$i] = true;
} else {
$check[$i] = false;
}
}
elseif ($filteroperator == 25) { // equal file
$file = $this->getParameter('filefilter_directory')."/".$filtervalue;
$fp = fopen($file,'r') or die("Can't open the file");
while($line = fgets($fp)) {
/* $find = array("\n", ",");
$line = str_replace($find,"",$line);
if (is_numeric($line)){*/
$line = str_replace("\n","",$line);
$filevalues[] = strtolower($line);
/* }
*/
}
if (in_array(strtolower($value),$filevalues)) {
$check[$i] = true;
} else {
$check[$i] = false;
}
fclose($fp) or die("Error closing the file");
}
elseif ($filteroperator == 26) { // not equal file
$file = $this->getParameter('filefilter_directory')."/".$filtervalue;
$fp = fopen($file,'r') or die("Can't open the file");
while($line = fgets($fp)) {
/* $find = array("\n", ",");
$line = str_replace($find,"",$line);
if (is_numeric($line)){*/
$line = str_replace("\n","",$line);
$filevalues[] = strtolower($line);
/* }
*/
}
if (!in_array(strtolower($value),$filevalues)) {
$check[$i] = true;
} else {
$check[$i] = false;
}
fclose($fp) or die("Error closing the file");
}
elseif ($filteroperator == 31) { // starts file with - string
$file = $this->getParameter('filefilter_directory')."/".$filtervalue;
$fp = fopen($file,'r') or die("Can't open the file");
$check[$i] = false;
while($line = fgets($fp) and $check[$i] == false) {
/* $find = array("\n", ",");
$line = str_replace($find,"",$line);
if (is_numeric($line)){*/
$line = str_replace("\n","",$line);
$filevalues[] = strtolower($line);
if (str_starts_with(strtolower($value), strtolower($line)) !== false) {
$check[$i] = true;
}
}
fclose($fp) or die("Error closing the file");
}
$i++;
}
$boolean = $fg->getBoolean();
if ($boolean == 0) { // all check must be true
if (in_array(false, $check)) {
$filtercheck = false;
} else {
$filtercheck = true;
}
} elseif ($boolean == 1) { // at least one check must be true
if (in_array(true, $check)) {
$filtercheck = true;
} else {
$filtercheck = false;
}
} elseif ($boolean == 2) { // all check must be false
if (in_array(true, $check)) {
$filtercheck = false;
} else {
$filtercheck = true;
}
}
$report = new Campaignfilterlog();
$report->setLead($lead);
$report->setFiltergroup($fg);
$report->setResult($filtercheck);
$report->setDate(time());
$em = $this->getDoctrine()->getManager();
$em->persist($report);
$em->flush();
if ($filtercheck == false) { // If only one filtergroup is false the loop blocks and return false
return $filtercheck;
}
}
} else {
$filtercheck = true;
}
}catch(\Exception $e){
$filtercheck = false;
}
return $filtercheck;
}
public function checkleadfield($fields, $data, $lead)
{
foreach ($fields as $field) {
$fieldname = $field->getName();
if ($field->getMandatory() == 1) {
if (isset($data[$fieldname])) {
if ($data[$fieldname] !== null && $data[$fieldname] !== '') {
$validator[] = $this->validator($data[$fieldname], $field);
//$leadfield = $this->leadfield($lead,$field,$data[$fieldname]);
} else {
$validator[] = false;
//$leadfield = $this->leadfield($lead,$field,$data[$fieldname]);
}
}
} else {
if (!isset($data[$fieldname])) {
$data[$fieldname] = null;
}
$validator[] = true;
}
//var_dump($data[$fieldname]);
$leadfield = $this->insertleadfield($lead, $field, $data[$fieldname]);
}
return $validator;
}
public function insertleadfield($lead, $field, $data)
{
$em = $this->getDoctrine()->getManager();
// Insert leadfields
$leadfield = new Leadfield();
$leadfield->setLead($lead);
$leadfield->setField($field);
$leadfield->setValue($data);
$em->persist($leadfield);
$em->flush();
}
public function insertlead($data, $project, $lead_status)
{
$em = $this->getDoctrine()->getManager();
// Mapping data
if (isset($data['email'])) {
$email = $data['email'];
} else {
$email = null;
}
if (isset($data['session'])) {
//$session = $data['session'];
$session = $this->getDoctrine()->getRepository(Session::class)->findOneById($data['session']);
} else {
$session = null;
}
if (isset($data['phone'])) {
$phone = $data['phone'];
} else {
$phone = null;
}
if (isset($data['ip'])) {
$ip = $data['ip'];
} else {
$ip = null;
}
if (isset($data['client'])) {
$client = $data['client'];
} else {
$client = null;
}
if (isset($data['referral'])) {
$referral = $data['referral'];
} else {
$referral = null;
}
if (isset($data['source']) && $data['source'] !== '') {
$source = $data['source'];
} else {
$source = null;
}
if (isset($data['sub1']) && $data['sub1'] !== '') {
$sub1 = $data['sub1'];
} else {
$sub1 = null;
}
if (isset($data['sub2']) && $data['sub2'] !== '') {
$sub2 = $data['sub2'];
} else {
$sub2 = null;
}
if (isset($data['sub3']) && $data['sub3'] !== '') {
$sub3 = $data['sub3'];
} else {
$sub3 = null;
}
if (isset($data['sub4']) && $data['sub4'] !== '') {
$sub4 = $data['sub4'];
} else {
$sub4 = null;
}
if (isset($data['clickid']) && $data['clickid'] !== '') {
$clickid = $data['clickid'];
} else {
$clickid = null;
}
if (isset($data['offer']) && $data['offer'] !== '') {
$offer = $data['offer'];
} else {
$offer = null;
}
if (isset($data['registrationdate']) && $data['registrationdate'] !== '') {
$registrationdate = new \Datetime('Europe/Madrid');
} else {
$registrationdate = new \Datetime();
$registrationdate->setTimezone(new \DateTimeZone('Europe/Madrid'));
}
// Insert tracking
if ($project->getTracking() !== null && $project->getTracking()->getId() !== 2 ) {
$tracking = new Hasoffers;
$tracking->setClickid($clickid);
$tracking->setOffer($offer);
$tracking->setSource($source);
$em->persist($tracking);
$em->flush();
} else {
$tracking = null;
}
// Create the Lead with basic data
$lead = new Lead();
$lead->setEmail($email);
$lead->setPhone($phone);
$lead->setSession($session);
$lead->setIp($ip);
$lead->setClient($client);
$lead->setReferral($referral);
$lead->setSource($source);
$lead->setSub1($sub1);
$lead->setSub2($sub2);
$lead->setSub3($sub3);
$lead->setSub4($sub4);
$lead->setProject($project);
$lead->setRegistrationdate(new \Datetime('Europe/Madrid'));
$lead->setStatus($lead_status);
$lead->setHs($tracking);
$em->persist($lead);
$em->flush();
return $lead;
}
public function feedback($resultin, $resultout, $lead = null, $price = 0)
{
if (isset($resultin['honeypot'])){
if ($resultin['honeypot'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'invalid user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['novalidproject'])) {
if ($resultin['novalidproject'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'id not passed or project doesn\'t exist',
//'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['inactive'])) {
if ($resultin['inactive'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'campaign not active',
//'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['invalidemail'])) {
if ($resultin['invalidemail'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'invalid email address',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['invaliddomain'])) {
if ($resultin['invaliddomain'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'invalid user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['duplicategen'])) {
if ($resultin['duplicategen'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'duplicate user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['api_project'])) {
if ($resultin['api_project'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'permission denied',
);
return $feedback;
}
}
if (isset($resultin['duplicate'])) {
if ($resultin['duplicate'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'duplicate user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['duplicateemailproject'])) {
if ($resultin['duplicateemailproject'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'duplicate user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['duplicateemailproject'])) {
if ($resultin['blacklist'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'blacklisted user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['fake'])) {
if ($resultin['fake'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'invalid user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['validproject'])) {
if ($resultin['validproject'] == false) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'some parameters don\'t match the target',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['inserted'])) {
if ($resultin['inserted'] == false) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'invalid user',
//'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['roifail'])) {
if ($resultin['roifail'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'invalid user',
//'lead id' => $lead->getId()
);
if (isset($lead)){
$feedback["lead id"] = $lead->getId();
}
return $feedback;
}
}
if ($resultout !== null) {
if (isset($resultout['validcampaign'])) {
if ($resultout['validcampaign'] == false) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'invalid user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultout['validcustomer'])) {
if ($resultout['validcustomer'] == false) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'invalid user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['duplicatetracking'])) {
if ($resultin['duplicatetracking'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'duplicate user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
if (isset($resultin['invalidtracking'])) {
if ($resultin['invalidtracking'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'invalid user',
'lead id' => $lead->getId()
);
return $feedback;
}
}
/* if (str_contains($lead->getEmail(), '@test.com') == true){
dd("hola",$resultout,$resultin);
}*/
}
if ($lead->getProject()->getId() == 65 || $lead->getProject()->getId() == 60){
$feedback = array(
'code' => 200,
'success' => true,
'message' => 'valid user',
'lead id' => $lead->getId(),
'price' => $price
);
}else{
$feedback = array(
'code' => 200,
'success' => true,
'message' => 'valid user',
'lead id' => $lead->getId()
);
}
return $feedback;
}
public function updateproject($project, $resultin, $revenue, $sold,$lead)
{
$em = $this->getDoctrine()->getManager();
$project->setRevenue($project->getRevenue() + $revenue);
$project->setSold($project->getSold() + $sold);
$project->setGross($project->getGross() + 1);
if ($resultin['duplicategen'] == true) {
$project->setDuplicategen($project->getDuplicategen() + 1);
return $project;
}
if ($resultin['duplicate'] == true) {
$project->setDuplicate($project->getDuplicate() + 1);
return $project;
}
if ($resultin['duplicatetracking'] == true) {
$project->setDuplicate($project->getDuplicate() + 1);
return $project;
}
if ($resultin['fake'] == true) {
$project->setFake($project->getFake() + 1);
return $project;
}
if ($lead->getStatus()->getId() == 2 ){
// If the lead is fully validated
$project->setValid($project->getValid() + 1);
$project->setCapreach($project->getCapreach() + 1);
//dd("hola",$project->getValid(),is_numeric($project->getCapping()));
if (is_numeric($project->getCapping()) ){
if ($project->getCapping() != 0){
if (($project->getCapping()<=$project->getCapreach())){
$capping = $this->getDoctrine()->getRepository(Status::class)->findOneById(12);
$project->setCapreach(0);
$project->setStatus($capping);
}
}
}
$project->setDailyreach($project->getDailyreach() + 1);
$project->setMonthlyreach($project->getMonthlyreach() + 1);
//$this->capping($project, 'project');
}else{
$project->setInvalid($project->getInvalid() + 1);
}
return $project;
}
public function capping($entity, $type)
{
$em = $this->getDoctrine()->getManager();
$active = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(1); // Valid lead status
$pause = $this->getDoctrine()->getRepository(Status::class)->findOneById(7); // Valid lead status
$valid = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // Valid lead status
// Calculate valid lead
if ($type == 'project') {
// Check general capping
$leads = $this->getDoctrine()->getRepository(Lead::class)->findBy(array
(
'project' => $entity,
'status' => $active
)
);
if ($entity->getCapping() !== null && count($leads) >= $entity->getCapping()) {
$entity->setStatus($pause);
return $entity;
}
// Check month capping
$fromdate = date('Y-m') . '-01 00:00:00';
$todate = date('Y-m-d') . ' 23:59:59';
$repository = $this->getDoctrine()->getRepository(Lead::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->leftJoin('App:Project', 'p', 'WITH', 'c.project = p.id');
$query->leftJoin('App:Status', 's', 'WITH', 'c.status = s.id');
$query->andWhere('p.id = :project');
$query->setParameter('project', $entity->getId());
$query->andWhere('s.id = :status');
$query->setParameter('status', 1);
$query->andWhere('c.registrationdate >= :fromdate');
$query->andWhere('c.registrationdate <= :todate');
$query->setParameter('fromdate', $fromdate);
$query->setParameter('todate', $todate);
$query = $query->getQuery();
$leads = $query->getResult();
if ($entity->getCapping() !== null && count($leads) >= $entity->getMonthlycapping()) {
$entity->setStatus($pause);
}
return $entity;
}elseif($type == "campaign"){
// Check general capping
$leads = $this->getDoctrine()->getRepository(Leadcampaign::class)->findBy(array
(
'campaign' => $entity,
'status' => $active
)
);
if ($entity->getCapping() != 0 && count($leads) >= $entity->getCapping()) {
return false;
}
// Check month capping
$fromdate = date('Y-m') . '-01 00:00:00';
$todate = date('Y-m-d') . ' 23:59:59';
$repository = $this->getDoctrine()->getRepository(Leadcampaign::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->leftJoin('App:Campaign', 'c', 'WITH', 'c.campaign = c.id');
$query->leftJoin('App:Leadstatus', 's', 'WITH', 'c.status = s.id');
$query->andWhere('c.id = :campaign');
$query->setParameter('campaign', $entity->getId());
$query->andWhere('s.id = :status');
$query->setParameter('status', 2);
$query->andWhere('c.registrationdate >= :fromdate');
$query->andWhere('c.registrationdate <= :todate');
$query->setParameter('fromdate', $fromdate);
$query->setParameter('todate', $todate);
$query = $query->getQuery();
$leads = $query->getResult();
if ($entity->getMonthlycapping() != 0 && count($leads) >= $entity->getMonthlycapping()) {
return false;
}
// Check daily capping
$fromdate = date('Y-m-d') . ' 00:00:00';
$todate = date('Y-m-d') . ' 23:59:59';
$repository = $this->getDoctrine()->getRepository(Leadcampaign::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->leftJoin('App:Campaign', 'c', 'WITH', 'c.campaign = c.id');
$query->leftJoin('App:Leadstatus', 's', 'WITH', 'c.status = s.id');
$query->andWhere('c.id = :campaign');
$query->setParameter('campaign', $entity->getId());
$query->andWhere('s.id = :status');
$query->setParameter('status', 2);
$query->andWhere('c.registrationdate >= :fromdate');
$query->andWhere('c.registrationdate <= :todate');
$query->setParameter('fromdate', $fromdate);
$query->setParameter('todate', $todate);
$query = $query->getQuery();
$leads = $query->getResult();
if ($entity->getDailycap() != 0 && count($leads) >= $entity->getDailycap()) {
return false;
}
return true;
}
return $entity;
}
public function validator($data, $field)
{
$v = $field->getValidator();
if ($v['operator'] == 'equal') {
if ($v['value'] == $data) {
return true;
} else {
return false;
}
} elseif ($v['operator'] == 'different') {
if ($v['value'] !== $data) {
return true;
} else {
return false;
}
} elseif ($v['operator'] == 'contains') {
if (strpos($data, $v['value']) !== false) {
return true;
} else {
return false;
}
} elseif ($v['operator'] == 'not contains') {
if (strpos($data, $v['value']) == false) {
return true;
} else {
return false;
}
} else {
return true;
}
}
public function hasoffertrk($lead,$data)
{
$em = $this->getDoctrine()->getManager();
$clickid = $lead->getHs()->getClickid();
$tracking = $lead->getHs();
$conn = $em->getConnection();
try {
if ($lead->getProject()->getRevenueShare()){
if ($lead->getProject()->getTypeRevenueShare()=="roi"){
$hasoffers = 'http://trk.loudedig.com/aff_lsr?amount='.$lead->getProject()->getRoi().'&transaction_id='.$clickid;
}else{
if ( $lead->getProject()->getTypeRevenueShare()=="lowest"){
$query = 'SELECT
MIN(revenue) price
FROM leadcampaign lc
WHERE lc.lead_id = :leadid
AND lc.revenue > :revenue
';
}elseif ($lead->getProject()->getTypeRevenueShare()=="average"){
$query = 'SELECT
AVG (revenue) price
FROM leadcampaign lc
WHERE lc.lead_id = :leadid
AND lc.revenue > :revenue
';
}elseif ($lead->getProject()->getTypeRevenueShare()=="highest"){
$query = 'SELECT
MAX(revenue) price
FROM leadcampaign lc
WHERE lc.lead_id = :leadid
AND lc.revenue > :revenue
';
}
$stmt = $conn->prepare($query);
$stmt->bindValue('leadid',$lead->getId() , 'string');
$stmt->bindValue('revenue', 0, 'string');
$stmt->execute();
$leadscampaigns = $stmt->fetchAll();
if ($lead->getProject()->getTypeRevenueShare() == "roi"){
$price=$lead->getProject()->getRoi();
}else{
$price=$leadscampaigns[0]['price'];
}
$hasoffers = 'http://trk.loudedig.com/aff_lsr?amount='.$price.'&transaction_id='.$clickid;
}
}elseif(str_contains($lead->getEmail(), '@loudingest.com') == true || str_contains($lead->getEmail(), '@loudingads.com') == true){
$hasoffers = 'http://trk.loudedig.com/aff_lsr?amount='.$lead->getProject()->getRoi().'&transaction_id='.$clickid;
}
} catch(\Exception $e) {
}
if (str_contains($lead->getEmail(), '@loudingads.com') == true){
$hasoffers = 'http://trk.loudedig.com/aff_lsr?amount='.$lead->getProject()->getRoi().'&transaction_id='.$clickid;
}
if (!isset($hasoffers)){
if ( $lead->getProject()->getId()==54 || $lead->getProject()->getId() == 56 || $lead->getProject()->getId()==57){
$query = 'SELECT
MIN(revenue) price
FROM leadcampaign lc
WHERE lc.lead_id = :leadid
AND lc.revenue > :revenue
';
$stmt = $conn->prepare($query);
$stmt->bindValue('leadid',$lead->getId() , 'string');
$stmt->bindValue('revenue', 0, 'string');
$stmt->execute();
$leadscampaigns = $stmt->fetchAll();
$price = $leadscampaigns[0]['price'];
$hasoffers = 'http://trk.loudedig.com/aff_lsr?amount='.$leadscampaigns[0]['price'].'&transaction_id='.$clickid;
}else{
$hasoffers = 'https://loudingads.go2cloud.org/aff_lsr?transaction_id=' . $clickid;
}
}
$hasoffers = file_get_contents($hasoffers);
$tracking->setResponse($hasoffers);
$em->persist($tracking);
$em->flush();
if (strpos($hasoffers, 'success=false') !== false) {
return null;
}
$cost = 'https://loudingads.api.hasoffers.com/Apiv3/json?NetworkToken=NETfLjuz52LTPJ2aOWXOruj7Lo7u7l&Target=Offer&Method=getAffiliatePayment&offer_id='.$data["offer"].'&affiliate_id='.$data["source"];
$response = file_get_contents($cost);
// Decode the response into a PHP associative array
$response = json_decode($response);
if (isset($response->response->data->payout_type)) {
if ($response->response->data->payout_type == "cpa_percentage") {
if (isset($price)){
try {
$price = $price*$response->response->data->percent_payout/100;
$response->response->data->price=$price;
}catch(\Exception $e){
}
}
}
}
return $response;
}
public function webservice($ws, $fields)
{
$em = $this->getDoctrine()->getManager();
$header = $ws->getHeader();
$url = $ws->getUrl();
$method = $ws->getMethod();
$fixed = $ws->getFields();
$f = array();
foreach ($fixed as $key => $value) {
$f[$value['field']] = $value['value'];
}
if (count($f) > 0) {
$fields = array_merge($fields, $f);
}
$ch = curl_init();
if ($method == 0) { // GET
$url = $url . '&' . http_build_query($fields);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
} else { // POST
if ($ws->getDatatype() == 1) {
$fields = json_encode($fields);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (count($header) > 0) {
foreach ($header as $h) {
$hd[] = $h['value'];
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $hd);
}
}
$response = curl_exec($ch);
if ($method == 0) {
$wscall = json_encode(curl_getinfo($ch), JSON_UNESCAPED_SLASHES);
} else {
if (count($header) == 0) {
$hd = null;
}
$wscall = json_encode(
array(
'header' => $hd,
'data' => $fields,
'call' => json_encode(curl_getinfo($ch))
, JSON_UNESCAPED_SLASHES)
);
}
$feedback = array(
'response' => $response,
'wscall' => $wscall
);
curl_close($ch);
return $feedback;
}
public function project(Request $request)
{
$data = $request->request->all();
if (isset($data['domain'])) {
$domain = $data['domain'];
} else {
$domain = null;
}
$em = $this->getDoctrine()->getManager();
$active = $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
$project = $this->getDoctrine()->getRepository(Project::class)->findOneBy(array(
'domain' => $domain,
'status' => $active
)
);
$headers = $this->getDoctrine()->getRepository(Header::class)->findBy(array(
'project' => $project,
'status' => $active
)
);
$h = array();
if (count($headers) > 0) {
foreach ($headers as $header) {
$h[] = array(
'name' => $header->getName(),
'code' => $header->getCode(),
'version' => $header->getVersion()
);
}
}
if ($project !== null) {
$project = array(
'id' => $project->getId(),
'name' => $project->getName(),
'country' => $project->getCountry()->getCode(),
'lang' => $project->getLang()->getCode(),
'header' => $h
);
} else {
$project = array(
'id' => null
);
}
return $this->json($project);
}
public function content(Request $request)
{
$data = $request->request->all();
$active = $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
if (isset($data['project'])) {
$project = $this->getDoctrine()->getRepository(Project::class)->findOneById($data['project']);
$contact = $this->getDoctrine()->getRepository(Projectmail::class)->findOneBy(array(
'project' => $project,
'status' => $active
));
$projectdata = array(
'id' => $project->getId(),
'name' => $project->getName(),
'country' => $project->getCountry()->getCode(),
'domain' => $project->getDomain(),
'contact' => $contact->getEmail()
);
} else {
$project = null;
$projectdata = null;
}
if (isset($data['type'])) {
$type = $this->getDoctrine()->getRepository(PageType::class)->findOneBy(array(
'name' => $data['type'],
));
} else {
$type = null;
}
$content = $this->getDoctrine()->getRepository(Page::class)->findOneBy(
array(
'project' => $project,
'type' => $type,
'status' => $active
)
);
if ($content !== null) {
$content = array(
'id' => $content->getId(),
'title' => $content->getName(),
'text' => $content->getText(),
'shortname' => $content->getShortname(),
'project' => $projectdata
);
} else {
$content = array(
'id' => null
);
}
return $this->json($content);
}
public function session(Request $request)
{
$data = $request->request->all();
if (isset($data['source']) && $data['source'] !== '') {
$source = $data['source'];
} else {
$source = null;
}
if (isset($data['ip']) && $data['ip'] !== '') {
$ip = $data['ip'];
} else {
$ip = null;
}
if (isset($data['sub1']) && $data['sub1'] !== '') {
$sub1 = $data['sub1'];
} else {
$sub1 = null;
}
if (isset($data['sub2']) && $data['sub2'] !== '') {
$sub2 = $data['sub2'];
} else {
$sub2 = null;
}
if (isset($data['sub3']) && $data['sub3'] !== '') {
$sub3 = $data['sub3'];
} else {
$sub3 = null;
}
if (isset($data['sub4']) && $data['sub4'] !== '') {
$sub4 = $data['sub4'];
} else {
$sub4 = null;
}
if (isset($data['cid']) && $data['cid'] !== '') {
$cid = $data['cid'];
} else {
$cid = null;
}
$em = $this->getDoctrine()->getManager();
$project = $this->getDoctrine()->getRepository(Project::class)->findOneById($data['project']);
$session = new Session();
$session->setProject($project);
$session->setSession($data['session']);
$session->setIp($ip);
$session->setReferral($data['referral']);
$session->setClient($data['client']);
$session->setTimestamp(new \Datetime('Europe/Madrid'));
$session->setSource($source);
$session->setSub1($sub1);
$session->setSub2($sub2);
$session->setSub3($sub3);
$session->setSub4($sub4);
$session->setCid($cid);
$em->persist($session);
$em->flush();
$result = array(
'id' => $session->getId()
);
return $this->json($result);
}
public function projectmail(Request $request)
{
$data = $request->request->all();
if (isset($data['project'])) {
$project = $this->getDoctrine()->getRepository(Project::class)->findOneById($data['project']);
} else {
$project = null;
}
if (isset($data['type'])) {
$type = $data['type'];
} else {
$type = null;
}
$em = $this->getDoctrine()->getManager();
$active = $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
$content = $this->getDoctrine()->getRepository(Projectmail::class)->findOneBy(
array(
'project' => $project,
'type' => $type,
'status' => $active
)
);
if ($content !== null) {
$content = array(
'id' => $content->getId(),
'email' => $content->getEmail()
);
} else {
$content = array(
'id' => null
);
}
return $this->json($content);
}
public function update(Request $request)
{
$em = $this->getDoctrine()->getManager();
$data = $request->request->all(); // Get all the data in the Request
// Get email from Request
if (isset($data['email'])) {
$email = $data['email'];
} else {
$email = null;
}
// Get project from Request
if (isset($data['project'])) {
$project = $data['project'];
} else {
$project = null;
}
// Get lead id from Request
if (isset($data['uid'])) {
$uid = $data['uid'];
} else {
$uid = null;
}
// Result array
$resultin = array(
'inactive' => false,
'duplicategen' => false,
'duplicate' => false,
'duplicatetracking' => false,
'fake' => false,
'validproject' => false,
'inserted' => false
);
$resultout = array(
'validcampaign' => false,
'validcustomer' => false
);
$active = $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
// Check project
$project = $this->getDoctrine()->getRepository(Project::class)->findOneBy(
array(
'id' => $project,
'status' => $active
)
);
// If project doesn't exist or is not active
if ($project == null) {
$resultin['inactive'] = true;
$result = $this->feedback($resultin, $resultout);
return $this->json($result);
}
// Check if email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$resultin['invalid'] = true;
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(3);
$lead = $this->insertlead($data, $project, $lead_status);
$result = $this->feedback($resultin, $resultout);
return $this->json($result);
}
// Get lead
$lead = $this->getDoctrine()->getRepository(Lead::class)->findOneById($uid);
if ($lead == null) {
return $this->json($resultin);
}
foreach ($data as $key => $value) {
// Get field
$field = $this->getDoctrine()->getRepository(Field::class)->findOneBy(array(
'project' => $project,
'status' => $active,
'name' => $key
)
);
if ($field !== null) {
// Get leadfield
$leadfield = $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(array(
'lead' => $lead,
'field' => $field
)
);
if ($leadfield->getValue() == null || $leadfield->getValue() == '') {
$leadfield->setValue($value);
$em->persist($leadfield);
$em->flush();
}
}
}
$result = $this->feedback($resultin, $resultout, $lead);
return $this->json($result);
}
public function emailcheck($email)
{
try {
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return 2;
}
$domain = explode('@', $email);
if (count(dns_get_record($domain[1], DNS_MX)) < 1) {
return 3;
}
}catch (\Exception $e){
return 3;
}
}
public function getstats(Request $request)
{
if ($request->request->get('fromdate') !== null) {
$fromdate = $request->request->get('fromdate');
}
if ($request->request->get('todate') !== null) {
$todate = $request->request->get('todate');
}
if ($request->request->get('campaign') !== null) {
$campaign = $request->request->get('campaign');
$campaign = $this->getDoctrine()->getRepository(Campaign::class)->findOneById($campaign);
}
if ($this->getUser()->getCompany()->getId() !== $campaign->getCompany()->getId()){
$result = array(
'success' => false,
'message' => 'Permission denied'
);
return $this->json($result);
}
$em = $this->getDoctrine()->getManager();
$active = $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
$fields = $this->getDoctrine()->getRepository(Fieldcampaign::class)->findBy(
array(
'campaign' => $campaign,
'status' => $active
)
);
$select = null;
$i = 1;
foreach ($fields as $field) {
$select .= '(
SELECT lf.value
FROM leadfield lf
LEFT JOIN fieldcampaign_field fcf on fcf.field_id = lf.field_id
LEFT JOIN fieldcampaign fc on fcf.fieldcampaign_id = fc.id
WHERE lf.lead_id = l.id and fc.id = ' . $field->getId() . '
) as ' . $field->getName() . ',';
$i++;
}
$query = 'SELECT
l.id,
lc.id as lcid,
l.email,
l.phone,
l.ip,
l.source,
lc.registrationdate as sysregdate,
' . $select . '
s.status
FROM leadcampaign lc
LEFT JOIN lead l on lc.lead_id = l.id
LEFT JOIN campaign c on lc.campaign_id = c.id
LEFT JOIN currency y on lc.currency_id = y.id
LEFT JOIN leadstatus s on lc.status_id = s.id
WHERE lc.campaign_id = :campaign
AND lc.registrationdate >= :fromdate
AND lc.registrationdate <= :todate
ORDER BY l.id asc
';
$conn = $em->getConnection();
$stmt = $conn->prepare($query);
$stmt->bindValue('campaign', $campaign->getId(), 'string');
$stmt->bindValue('fromdate', $fromdate, 'string');
$stmt->bindValue('todate', $todate, 'string');
$stmt->execute();
$leads = $stmt->fetchAll();
//Voltalia Change mehdi source
try {
if ($campaign->getId() == 315){
foreach ($leads as $lead){
if ($lead["source"] == 1674){
$lead["source"] = "3184";
}
}
}
} catch (\Exception $e){
}
return $this->json($leads);
}
public function getThankYouPage(Request $request)
{
$data = $request->request->all();
$project = $this->getDoctrine()->getRepository(Project::class)->findOneById($data['project']);
$thankyou = $this->getDoctrine()->getRepository(ThankYou::class)->findOneBy(
['project' => $data['project'],
'status' => [1]],
['id' => 'DESC']
);
$campaigns = [];
if(count($project->getCampaignThankYou()) == 0) {
$thpgs = array();
$thpgs[0]['tytitle'] = $thankyou->getTitle();
$thpgs[0]['tydescription'] = $thankyou->getDescription();
$thpgs[0]['tyid'] = $thankyou->getId();
return $this->json($thpgs);
}
foreach ($project->getCampaignThankYou() as $campaign) {
if ($campaign->getStatus()->getId() == 1) {
array_push($campaigns, $campaign);
}
}
$thpgs = array();
$i = 0;
if ($campaigns==null){
$thpgs[$i]['tytitle'] = $thankyou->getTitle();
$thpgs[$i]['tydescription'] = $thankyou->getDescription();
$thpgs[$i]['tyid'] = $thankyou->getId();
}else{
foreach ($campaigns as $thpg) {
if ($thpg != null) {
$thpgs[$i]['title'] = $thpg->getTitle();
$thpgs[$i]['tytitle'] = $thankyou->getTitle();
$thpgs[$i]['subtitle'] = $thpg->getSubtitle();
$thpgs[$i]['url'] = $thpg->getURL();
$thpgs[$i]['image'] = $thpg->getImage();
$thpgs[$i]['description'] = $thpg->getDescription();
$thpgs[$i]['tydescription'] = $thankyou->getDescription();
$thpgs[$i]['tyid'] = $thankyou->getId();
$thpgs[$i]['calltoaction'] = $thpg->getCalltoaction();
$thpgs[$i]['status'] = $thpg->getStatus();
}
$i++;
}
}
return $this->json($thpgs);
}
public function sendToServer($lead){
$servers=$this->getDoctrine()->getRepository(ServerToServer::class)->findBy(array(
'project' => $lead->getProject(),
'status' => 1
));
foreach ($servers as $server) {
if ($lead->getSource() == $server->getSource()->getExternalid()) {
$webservice = "";
if ($server->getSource()->getStatus()->getId() == 1) {
switch ($server->getCode()) {
case "isolatiefacebook": // Loudingads leadgen ES
$webservice = $this->forward('App\Controller\ServerLogServiceController::isolatiefacebook', array('email' => $lead->getEmail()))->getContent();
break;
}
if ($webservice != "") {
$webservice = json_decode($webservice);
$log = new ServerToServerLog();
$log->setDate(time());
$log->setResponse($webservice);
$log->setServer($server);
$log->setLead($lead);
$em = $this->getDoctrine()->getManager();
$em->persist($log);
$em->flush();
}
}
}
}
}
public function validatedoiemail(Request $request){
$lead = $request->request->get("uuid");
$lead=urldecode($lead);
if (str_contains($lead," ")){
$lead= str_replace(" ","+",$lead);
}
$decrypt = openssl_decrypt(
$lead,
"aes128",
"vLjow7178",
0,
$iv="7983248923794221"
);
$log = $this->getDoctrine()->getRepository(DoiLogs::class)->findOneBy(
array(
'lead' => $decrypt,
)
);
$lead = $this->getDoctrine()->getRepository(Lead::class)->findOneBy(
array(
'id' => $decrypt,
)
);
/* if ($lead=="UiuK6yeLgJ7fVm9fscXStw=="){
dd("holi",$decrypt." nada", $log);
}*/
$validate = 0;
if ($log!=null){
if ($log->getConfirmation() != 1 ){
$log->setConfirmationdate(time());
$log->setResponse("true");
$log->setConfirmation(1);
$em = $this->getDoctrine()->getManager();
$em->persist($log);
$em->flush();
$validate = 1;
//we should send the lead to the doubleoptime campaigns here
$data["offer"] =strval( $this->getDoctrine()->getRepository(Hasoffers::class)->findOneById(
array(
'id' => $lead->getHs(),
)
)->getOffer());
//$input = 'https://www.blablablabla/h4/?offer=2312&source=4321&sub1=23848251207530664&[…]1237&utm_medium=email&utm_campaign=0&utm_content=v4';
//
//parse_str(parse_url($input, PHP_URL_QUERY), $results);
//
//var_dump($results);
//Example:
//$input= "https://zonnepanelen.verbouwingsadviseur.eu/v4/?offer=3080&source=1237&sub1=23848251207530664&cid=10213b1f54197fde76dddf094c03e3&utm_source=1237&utm_medium=email&utm_campaign=0&utm_content=v4";
//parse_str(parse_url($input, PHP_URL_QUERY), $results);
//
//var_dump($results["offer"],$results["source"]);
$data["source"]=$lead->getSource();
$project = $this->getDoctrine()->getRepository(Lead::class)->findOneBy(
array(
'id' => $decrypt,
)
)->getProject();
$repository = $this->getDoctrine()->getRepository(Campaign::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->leftJoin('App:Status', 's', 'WITH', 'c.status = s.id');
$query->leftJoin('App:LeadVerification', 'lv', 'WITH', 'c.sending = lv.id');
$query->andWhere(':project MEMBER OF c.project');
$query->setParameter('project', $project->getId());
$query->andWhere('s.id = :status');
$query->setParameter('status', 1);
$query->andWhere('lv.id = :verification');
$query->setParameter('verification', 2);
$query = $query->getQuery();
$campaigns = $query->getResult();
if (count($campaigns) != 0){
$resultout = $this->export($lead, $project, $campaigns);
$revenue = $resultout['revenue'];
$resultin["invaliddomain"] = false;
$resultin["invalidemail"] = false;
$resultin["duplicategen"] = false;
$resultin["duplicate"] = false;
$resultin["duplicatetracking"] = false;
$resultin["validproject"] = true;
$resultin["fake"] = false;
$resultin["roifail"] = false;
$sold = $resultout['sold'];
$lead->setRevenue($revenue);
if ($lead->getRevenue() < $project->getRoi()) {
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(16); // roi fail
$lead->setStatus($lead_status); // roi not reached
$resultin['roifail'] = true;
$em->persist($lead);
$em->flush();
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold); // End of process
return $result;
} else {
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // valid lead
$lead->setStatus($lead_status); // roi reached
}
if ($lead->getHs() != null) { // Only if the campaign is tracked in HasOffers
$tracking = $this->hasoffertrk($lead, $data);
if ($tracking !== null) {
if (isset($tracking->response->data->payout)){
$cost = $tracking->response->data->payout;
if (isset($tracking->response->data->price)){
$cost = $tracking->response->data->price;
}
if ($cost == null) {
$cost = 0;
}
}else{
$cost=0;
}
$lead->setCost(floatval($cost));
} else { // If HasOffers reject the lead as duplicate
if ($lead->getStatus()->getId() == 1 || $lead->getStatus()->getId() == 1 ){
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6);
$lead->setStatus($lead_status); // duplicate lead
//$resultin['duplicatetracking'] = true;
$resultin['invalidtracking'] = true;
}
}
} else {
$lead_status = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(1);
$lead->setStatus($lead_status); // active lead
}
$em->persist($lead);
$em->flush();
$result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
return $this->json(1);
}
}else{
$validate=0;
}
}else{
$validate=0;
}
return $this->json($validate);
}
public function getUrlRedirection(Request $request){
$data = $request->request->all();
$campaign = $this->getDoctrine()->getRepository(Campaign::class)->findOneById(376);
$lead = $this->getDoctrine()->getRepository(Lead::class)->findOneById($data["leadid"]);
$wslog = $this->getDoctrine()->getRepository(Wslog::class)->findOneBy(
array(
'campaign' => $campaign,
'lead' => $data["leadid"]
)
);
if($wslog !== null && $wslog->getFeedback() !== null) {
$feedbackwslog = json_decode($wslog->getFeedback());
$redirectURL = $feedbackwslog->redirect_url;
} else {
$redirectURL = 0;
}
return $this->json($redirectURL);
}
public function redirectmeilleaurtaux(Request $request){
$data = $request->request->all();
$feedback = json_decode($data["result"]);
$campaign = $this->getDoctrine()->getRepository(Campaign::class)->findOneById(263);
$lead = $this->getDoctrine()->getRepository(Lead::class)->findOneById($feedback->leadid);
$wslog = $this->getDoctrine()->getRepository(Wslog::class)->findOneBy(
array(
'campaign' => $campaign,
'lead' => $lead
)
);
if($wslog !== null && $wslog->getFeedback() !== null) {
$feedbackwslog = json_decode($wslog->getFeedback());
$redirectURL = $feedbackwslog->RedirectUrl;
} else {
$redirectURL = 0;
}
return $this->json($redirectURL);
}
// Antifraud system
public function antifraud($lead, $data) {
// Check project fraud system
$em = $this->getDoctrine()->getManager();
if($lead->getProject()->getAppFraud() !== null) { // Check if there's an antifraud system
if(isset($data['antifraudid']) == true) { // Check if data has anifraud id
if($lead->getProject()->getAppFraud() !== null) { // Check if project has antifraud
if($lead->getProject()->getAppFraud()->getId() == 1) { // Opticks antifraud system
// Opticks
$opticks = new AppOpticksController($em); // invoke controller
$fraudcheck = $opticks->leadcheck($lead->getProject()->getAppFraud(), $data['antifraudid'], $lead);
}elseif ($lead->getProject()->getAppFraud()->getId() == 4){
//Recaptcha
$recaptcha = new RecaptchaController($em); // invoke controller
$fraudcheck = $recaptcha->leadcheck($lead->getProject()->getAppFraud(), $data['tokenrecaptcha'], $lead);
}
return $fraudcheck; // Antifraud entity
}
}elseif (isset($data['tokenrecaptcha']) == true){
if($lead->getProject()->getAppFraud() !== null) { // Check if project has antifraud
if ($lead->getProject()->getAppFraud()->getId() == 4){
$recaptcha = new RecaptchaController($em); // invoke controller
$fraudcheck = $recaptcha->leadcheck($lead->getProject()->getAppFraud(), $data['tokenrecaptcha'], $lead);
return $fraudcheck; // Antifraud entity
}
}
}
}
return null;
}
public function sellping($lead,$project,$campaigns,$test,$ping, $apiinboundtraffic){
$em = $this->getDoctrine()->getManager();
$feedback = '';
$allresultsping = array(); // array with the collection of the results of all customer's ping response
$pingresults = array(); // only with the prices to display to the publihers
$counter = 0;
if($project->getCommissions() !== null) {
$commission = $project->getCommissions();
} else {
$commission = 1;
}
foreach ($campaigns as $campaign){
$this->mergefields($project,$campaign,$lead);
$filterresult = $this->checkcampaignfilter($lead, $campaign);
if ($filterresult == true){
$resultoutPing = $this->exportInboundPing($ping,$project,$campaign);
if ($resultoutPing['price'] == 0 || $resultoutPing['check'] == 0){ // Ping not accepted
unset($campaigns[$counter]);
} elseif (($project->getMinimumPrice() !== null && $project->getMinimumPrice() !== '0') && $project->getMinimumPrice() > $resultoutPing['price']){ // Ping price below
unset($campaigns[$counter]);
} else {
$pingaccepted = array(
'price' => $resultoutPing['price'],
'campaign' => $campaign->getId(),
'pingid' => $resultoutPing['pingid']
);
array_push($allresultsping,$pingaccepted);
$pingresults[] = array(
'value' => round(($pingaccepted['price'] * $commission / 100),2),
'currency' => $project->getCurrency()->getSymbol()
);
$counter++; // add a counter only if the ping is been accepted
}
}
}
try {
usort($allresultsping, function (array $a, array $b) { return $b['price'] <=> $a['price']; });
}catch(\Exception $e){
$process_success = $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(4); // error
$publisherprice = '0.00';
$apiinboundtraffic->setStatus($process_success);
$em->persist($apiinboundtraffic);
$ping->setStatus($process_success);
$em->persist($ping);
$resultin['validlead'] = false;
$em->flush();
return $this->clientfeedback($resultin,$apiinboundtraffic,$ping,$publisherprice,$pingresults);
}
// Calculate price to
try {
$price = $allresultsping[0]['price'];
$publisherprice = round(($price * $commission / 100),2);
$process_success = $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(6); // success
$ping->setPricein($price);
$ping->setPriceout($publisherprice);
//good ping
$resultin['validlead'] = true;
}catch (\Exception $e){
$publisherprice = '0.00';
$process_success = $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(4); // error
$resultin['validlead'] = false;
}
//$resultin['validping'] = true; // display multiple results
$apiinboundtraffic->setStatus($process_success);
$em->persist($apiinboundtraffic);
$ping->setStatus($process_success);
$em->persist($ping);
$em->flush();
$result = $this->clientfeedback($resultin,$apiinboundtraffic,$ping,$publisherprice,$pingresults);
return $result;
}
public function mergefields($project, $campaign,$lead){
$status = $this->getDoctrine()->getRepository(Status::class)->findOneById(1); // active
$fieldscampaign = $this->getDoctrine()->getRepository(Fieldcampaign::class)->findBy(
array(
'status' => $status,
'campaign' => $campaign
)
);
$fields = array();
foreach ($fieldscampaign as $fc) {
$repository = $this->getDoctrine()->getRepository(Field::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->andWhere(':fieldcampaign MEMBER OF c.fieldcampaigns');
$query->setParameter('fieldcampaign', $fc->getId());
$query->andWhere('c.project = :project');
$query->setParameter('project', $project->getId());
$query = $query->getQuery();
$field = $query->getResult();
$fcvalue = $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(
array(
'field' => $field,
'lead' => $lead
)
);
if ($fcvalue !== null) {
$fields[$fc->getName()] = $fcvalue->getValue();
} else {
$fields[$fc->getName()] = null;
}
$fields["original_lead_id"] = $lead->getId();
}
return $fields;
}
public function setTestlead($value) {
$this->testlead = $value;
}
public function setTestwebservice($value) {
$this->testwebservice = $value;
}
public function setApiInboundTraffic(Request $request){
$em = $this->getDoctrine()->getManager();
// Register inbound call details
$entity = new ApiInboundTraffic();
$entity->setHeaders($request->headers);
$entity->setTimestamp(time());
$entity->setData(json_encode($request->request->all()));
$entity->setMethod($request->server->all()["REQUEST_METHOD"]);
$entity->setEndpoint($request->server->all()["REQUEST_URI"]);
$entity->setIp($request->server->all()["REMOTE_ADDR"]);
$entity->setUser($this->getUser());
$active = $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(1); // active process
$entity->setStatus($active);
$em->persist($entity);
$em->flush();
return $entity;
}
public function insertping($data, $project, $status,$apiinboundtraffic)
{
$em = $this->getDoctrine()->getManager();
// Mapping data
/*if (isset($data['ip'])) {
$ip = $data['ip'];
} else {
$ip = null;
}
if (isset($data['source']) && $data['source'] !== '') {
$source = $data['source'];
} else {
$source = null;
}
if (isset($data['url']) && $data['url'] !== '') {
$url = $data['url'];
} else {
$url = null;
}
/*if (isset($data['registrationdate']) && $data['registrationdate'] !== '') {
$registrationdate = new \Datetime($data['registrationdate']);
} else {
$registrationdate = new \Datetime();
$registrationdate->setTimezone(new \DateTimeZone('Europe/Madrid'));
}*/
// Create the Ping with basic data
$date = time();
$ping = new Ping();
$ping->setProject($project);
$ping->setStatus($status);
//$ping->setRegistrationdate($registrationdate);
$ping->setTimestamp($date);
//$ping->setSource($source);
//$ping->setIp($ip);
//$ping->setUrl($url);
$ping->setPingtoken(md5(uniqid('varus',true)));
$ping->setApiinboundtraffic($apiinboundtraffic);
$em->persist($ping);
$em->flush();
//$ping->setPingtoken(md5('varus'.$date.''.$ping->getId()));
//$em->persist($ping);
//$em->flush();
//$apiinboundtraffic->setPing($ping);
//$em->persist($apiinboundtraffic);
//$em->flush();
return $ping;
}
public function exportInboundPing($ping,$project,$campaign){
$em = $this->getDoctrine()->getManager();
$status = $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
$result = array(
'price' => 0,
'response' => '',
'pingid' => ''
);
// Get all Fieldcampaign
$fieldscampaign = $this->getDoctrine()->getRepository(Fieldcampaign::class)->findBy(
array(
'status' => $status,
'campaign' => $campaign
)
);
$fields = array();
// Get the connected Field for each Fieldcampaign
foreach ($fieldscampaign as $fc) {
$repository = $this->getDoctrine()->getRepository(Field::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->andWhere(':fieldcampaign MEMBER OF c.fieldcampaigns');
$query->setParameter('fieldcampaign', $fc->getId());
$query->andWhere('c.project = :project');
$query->setParameter('project', $project->getId());
$query = $query->getQuery();
$field = $query->getResult();
// Get Pingfield associated with each Field
$fcvalue = $this->getDoctrine()->getRepository(Pingfield::class)->findOneBy(
array(
'field' => $field,
'ping' => $ping
)
);
if ($fcvalue !== null) {
$fields[$fc->getName()] = $fcvalue->getValue();
} else {
$fields[$fc->getName()] = null;
}
}
$fields['original_lead_id'] = $ping->getId();
$test = false;
//$webservice = $this->forward('App\Controller\WebservicePingPostController::'.$campaign->getFunction().'ping', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
if($campaign->getStatus()->getId() == 9) { // Campaign in test mode
$test = true;
}elseif( $fields["firstname"] == "test" ) { // Campaign in test mode
$test = true;
}else {
$test = false;
}
$webservice = $this->forward('App\Controller\WebServicePingPostController::ping_'.$campaign->getId(), array('data' => $fields, 'campaign' => $campaign->getId(), 'test' => $test))->getContent();
try {
$result['response'] = $webservice;
$webservice = json_decode($webservice);//price,response,wscall,check
// Insert the result of the web service call of a single Campaign
$typecall = $this->getDoctrine()->getRepository(WslogCallType::class)->findOneById(1); // Ping
$result['price'] = $webservice->price;
$result['pingid'] = $webservice->pingid;
$wslog = new WslogInboundPing();
$wslog->setCampaign($campaign);
$wslog->setPing($ping);
$wslog->setResponse($webservice->check);
//$wslog->setType($ws->getMethod());
$wslog->setTypecall($typecall);
$wslog->setFeedback($webservice->response);
//$wslog->setTimestamp(new \Datetime('Europe/Madrid'));
$wslog->setTimestamp(time());
$wslog->setWscall(json_encode($webservice->wscall, JSON_UNESCAPED_SLASHES));
$wslog->setClientpingid($webservice->pingid);
$wslog->setPrice($webservice->price);
$em->persist($wslog);
$em->flush();
$result["check"] = $webservice->check;
}catch (\Exception $e){
$feedback = array(
'error' => $e->getMessage(),
'line' => $e->getLine(),
'file' => $e->getFile()
);
$wslog = new WslogInboundPing();
$wslog->setCampaign($campaign);
$wslog->setPing($ping);
$wslog->setResponse(0);
if (isset($webservice)){
if (isset($webservice->response)){
$wslog->setFeedback($webservice->response);
}elseif (isset($webservice)){
$wslog->setFeedback($webservice);
}elseif(isset($result['response'])){
$wslog->setFeedback($result['response']);
}else{
$wslog->setFeedback("no webservice");
}
}
//$wslog->setType($ws->getMethod());
$wslog->setTypecall($typecall);
//$wslog->setTimestamp(new \Datetime('Europe/Madrid'));
$wslog->setTimestamp(time());
$wslog->setWscall(json_encode($feedback), JSON_UNESCAPED_SLASHES);
$wslog->setPrice(0);
$em->persist($wslog);
$em->flush();
$result["check"] = 0;
}
return $result;
}
public function clientfeedback($resultin,$apiinboundtraffic, $enity = null, $price = 0, $pingresults = null)
{
$em = $this->getDoctrine()->getManager();
$feedback = '';
if (isset($resultin['validlead'])) {
if ($resultin['validlead'] == true) {
$feedback = array(
'code' => 200,
'success' => true,
'message' => 'Valid Ping',
'ping' => $enity->getPingtoken(),
//'price' =>($price/100*$ping->getProject()->getCommissions()),
'price' => array(
'value' => $price,
'currency' => $enity->getProject()->getCurrency()->getSymbol()
),
);
}
} elseif (isset($resultin['validping'])) {
if ($resultin['validping'] == true) {
$feedback = array(
'code' => 200,
'success' => true,
'message' => 'Valid Ping',
'ping' => $enity->getPingtoken(),
//'price' =>($price/100*$ping->getProject()->getCommissions()),
'price' => array(
'value' => $price,
'currency' => $enity->getProject()->getCurrency()->getSymbol()
),
'customers' => $pingresults
);
}
} elseif (isset($resultin['validpost'])) {
if ($resultin['validpost'] == true) {
$feedback = array(
'code' => 200,
'success' => true,
'message' => 'Valid Post',
'ping' => $enity->getPing()->getPingtoken(),
'post' => $enity->getPostToken(),
//'price' =>($price/100*$ping->getProject()->getCommissions()),
//'currency' => $ping->getProject()->getCurrency()->getSymbol()
'price' => array(
'value' => $price,
'currency' => $enity->getProject()->getCurrency()->getSymbol()
),
);
}
}elseif (isset($resultin['leadrejected'])) {
if ($resultin['leadrejected'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'lead' => $enity->getId(),
'message' => 'Post rejected by our buyers',
'price' => array(
'value' => $price,
'currency' => $enity->getProject()->getCurrency()->getSymbol()
),
);
}
}elseif (isset($resultin['pingrejected'])) {
if ($resultin['pingrejected'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'ping' => $enity->getPing()->getPingtoken(),
'message' => 'No buyers found'
);
}
}elseif (isset($resultin['doubleping'])) {
if ($resultin['doubleping'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'ping' => $enity->getPing()->getPingtoken(),
'message' => 'Duplicate pingid'
);
}
}elseif (isset($resultin['fieldsdoesntmatch'])) {
if ($resultin['fieldsdoesntmatch'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'ping' => $enity->getPing()->getPingtoken(),
'message' => 'Values doesn\'t match with the ping values',
'price' => array(
'value' => $price,
'currency' => $enity->getProject()->getCurrency()->getSymbol()
),
);
}
}elseif (isset($resultin['nopingidassociated'])) {
if ($resultin['nopingidassociated'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'ping' => $enity,
//'post' => $ping->getPostToken(),
'message' => 'Wrong ping id'
);
}
}elseif (isset($resultin['missingpingid'])) {
if ($resultin['missingpingid'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'Missing pingid'
);
}
}elseif (isset($resultin['pingsrejected'])) {
if ($resultin['pingsrejected'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'No buyers found',
'ping' => $enity->getPingtoken(),
'price' => $price,
'price' => array(
'value' => $price,
'currency' => $enity->getProject()->getCurrency()->getSymbol()
),
);
}
}elseif (isset($resultin['invalidproject'])) {
if ($resultin['invalidproject'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'Access denied',
//'lead id' => $lead->getId()
);
}
}elseif (isset($resultin['notallowedprojectstatus'])) {
if ($resultin['notallowedprojectstatus'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'not allowed to send leads to this project',
//'lead id' => $lead->getId()
);
}
}elseif (isset($resultin['clientnoaccess'])) {
if ($resultin['clientnoaccess'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'Access denied',
//'lead id' => $lead->getId()
);
}
}elseif (isset($resultin['filterprojecterror'])) {
if ($resultin['filterprojecterror'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'User out of target',
'ping' => $enity->getPingtoken(),
'price' => array(
'value' => $price,
'currency' => $enity->getProject()->getCurrency()->getSymbol()
),
);
}
}elseif (isset($resultin['nobuyer'])) {
if ($resultin['nobuyer'] == true) {
$feedback = array(
'code' => 404,
'success' => false,
'message' => 'No buyers found',
'ping' => $enity->getPingtoken(),
//'price' => $price
'price' => array(
'value' => $price,
'currency' => $enity->getProject()->getCurrency()->getSymbol()
),
);
}
}
$apiinboundtraffic->setResponse(json_encode($feedback));
$em->persist($apiinboundtraffic);
$em->flush();
return $feedback;
}
public function exportInboundPost($lead,$project,$campaign,$post){
$em = $this->getDoctrine()->getManager();
$status = $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
// Create empty array for response
$result = array(
'price' => 0,
'check' => 0,
'response' => null,
'pingid' => null,
'wslog' => null
);
// Get all Fieldcampaign for this Campaign
$fieldscampaign = $this->getDoctrine()->getRepository(Fieldcampaign::class)->findBy(
array(
'status' => $status,
'campaign' => $campaign
)
);
$fields = array();
foreach ($fieldscampaign as $fc) {
// Get the corresponding Field for each Fieldcampaign
$repository = $this->getDoctrine()->getRepository(Field::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c');
$query->andWhere(':fieldcampaign MEMBER OF c.fieldcampaigns');
$query->setParameter('fieldcampaign', $fc->getId());
$query->andWhere('c.project = :project');
$query->setParameter('project', $project->getId());
$query = $query->getQuery();
$field = $query->getResult();
$fcvalue = $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(
array(
'field' => $field,
'lead' => $lead
)
);
if ($fcvalue !== null) {
$fields[$fc->getName()] = $fcvalue->getValue();
} else {
$fields[$fc->getName()] = null;
}
}
$fields['original_lead_id'] = $lead->getId();
$buyer = $this->getDoctrine()->getRepository(WslogInboundPing::class)->findOneBy(
array(
'ping' => $post->getPing(),
'response' => 1,
'campaign' => $campaign
),
//1
);
$fields['pingid'] = $buyer->getClientpingid();
if($campaign->getStatus()->getId() == 9) {
$test = true;
}else {
$test = false;
}
//$webservice = $this->forward('App\Controller\WebservicePingPostController::'.$campaign->getFunction().'post', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
$webservice = $this->forward('App\Controller\WebServicePingPostController::post_'.$campaign->getId(), array('data' => $fields, 'campaign' => $campaign->getId(),'test'=> $test))->getContent();
$typecall = $this->getDoctrine()->getRepository(WslogCallType::class)->findOneById(2);
//if(json_last_error() === JSON_ERROR_NONE) {
try {
$result['response'] = $webservice;
$webservice = json_decode($webservice); // header, post, ch, response, check, price, leadid
$wslog = null;
$result['price'] = $webservice->price;
$result['pingid'] = $fields['pingid'];
$result['check'] = $webservice->check;
$wslog = new Wslog2();
$wslog->setCampaign($campaign);
$wslog->setLead($lead);
$wslog->setResponse($webservice->check);
//$wslog->setType($ws->getMethod());
$wslog->setTypecall($typecall);
$wslog->setFeedback($webservice->response);
//$wslog->setTimestamp(new \Datetime('Europe/Madrid'));
$wslog->setTimestamp(time());
$wslog->setWscall(json_encode($webservice->wscall, JSON_UNESCAPED_SLASHES));
$wslog->setPost($post);
$em->persist($wslog);
$em->flush();
} catch (\Exception $e){
$feedback = array(
'error' => $e->getMessage(),
'line' => $e->getLine(),
'file' => $e->getFile()
);
$errormessage = $e->getLine() . ' ' . $e->getMessage();
$result['check'] = 0;
$wslog = new Wslog2();
$wslog->setCampaign($campaign);
$wslog->setLead($lead);
$wslog->setResponse(0);
//$wslog->setType($ws->getMethod());
$wslog->setTypecall($typecall);
$wslog->setFeedback($errormessage);
//$wslog->setTimestamp(new \Datetime('Europe/Madrid'));
$wslog->setTimestamp(time());
$wslog->setWscall(json_encode($feedback), JSON_UNESCAPED_SLASHES);
$wslog->setPost($post);
$em->persist($wslog);
$em->flush();
}
//}
$result['wslog'] = $wslog;
return $result;
}
public function insertpost($data,$project,$apiinboundtraffic,$ping) {
$em = $this->getDoctrine()->getManager();
$status = $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(1); // active process
// Mapping data
/*if (isset($data['ip'])) {
$ip = $data['ip'];
} else {
$ip = null;
}
if (isset($data['source']) && $data['source'] !== '') {
$source = $data['source'];
} else {
$source = null;
}
if (isset($data['url']) && $data['url'] !== '') {
$url = $data['url'];
} else {
$url = null;
}
if (isset($data['registrationdate']) && $data['registrationdate'] !== '') {
$registrationdate = new \Datetime($data['registrationdate']);
} else {
$registrationdate = new \Datetime();
$registrationdate->setTimezone(new \DateTimeZone('Europe/Madrid'));
}
if (isset($data['project']) && $data['project'] !== '') {
$project = $this->getDoctrine()->getRepository(Project::class)->findOneById($data["project"]);
}*/
// Create the Ping with basic data
$post = new Post();
if (isset($project)){
$post->setProject($project);
}
$post->setStatus($status);
//$post->setRegistrationdate($registrationdate);
$post->setTimestamp(time());
//$post->setSource($source);
$post->setPing($ping);
//$post->setUrl($url);
$post->setApiinboundtraffic($apiinboundtraffic);
$em->persist($post);
$em->flush();
$post->setPosttoken(md5('varus'.time().''.$post->getId()));
$em->persist($post);
$em->flush();
//$apiinboundtraffic->setPost($post);
//$em->persist($apiinboundtraffic);
//$em->flush();
return $post;
}
public function setLeadcampaign($leadcampaign,$status,$lead,$campaign,$price = 0,$wslog) {
$em = $this->getDoctrine()->getManager();
if($leadcampaign == null) {
$leadcampaign = new Leadcampaign();
}
$leadcampaign->setLead($lead);
$leadcampaign->setCampaign($campaign);
$leadcampaign->setCurrency($campaign->getCurrency());
$leadcampaign->setRevenue($price);
$leadcampaign->setReason('pingpost');
$leadcampaign->setWslog2($wslog);
$leadcampaign->setStatus($status);
$leadcampaign->setTimestamp(time());
$em->persist($leadcampaign);
$em->flush();
return $leadcampaign;
}
public function sellpost($project,$data,$apiinboundtraffic,$ping,$lead){
$allresultspost = array(); // array with the collection of the results of all customer's ping response
$postresults = array(); // only with the prices to display to the publihers
$counter = 0;
if($project->getCommissions() !== null) {
$commission = $project->getCommissions();
} else {
$commission = 0;
}
$post = $this->insertpost($data,$project,$apiinboundtraffic,$ping);
$buyers = $this->getDoctrine()->getRepository(WslogInboundPing::class)->findBy(
array(
'ping' => $post->getPing(),
'response' => 1
),
array('price' => 'asc'),
//1
);
$campaignsprice = array();
foreach($buyers as $buyer){
$campaignprice = array(
"id" => $buyer->getCampaign()->getId(),
"price" => (int)$buyer->getPrice(),
);
array_push($campaignsprice,$campaignprice);
}
usort($campaignsprice, function (array $a, array $b) { return $b['price'] <=> $a['price']; });
$singlesellcampaign = $campaignsprice[0]["id"];
$campaigns= array();
foreach ($campaignsprice as $campaign){
$wsping = $this->getDoctrine()->getRepository(WslogInboundPing::class)->findOneBy(
array(
'ping' => $post->getPing(),
'response' => 1,
'campaign' => $campaign
),
);
array_push($campaigns,$wsping);
}
foreach ($campaigns as $buyer){
if ($counter<1){
$centinel = false ;
if (isset($data['test']) && $data['test'] == 1) {
$centinel = true;
} elseif($project->getStatus()->getId() == 9) {
$centinel = true;
}
if($buyer->getCampaign()->getStatus()->getId() == 1 || $buyer->getCampaign()->getStatus()->getId() == 9 || $centinel == true) {
$resultoutPost = $this->exportInboundPost($lead, $project, $buyer->getCampaign(),$post);
if ($resultoutPost['check'] === 0){
//unset($buyers[$counter]);
}else{ // Post accepted
// Set Leadcampaign
$leadcampaign = new Leadcampaign();
$validlead = $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // valid
$this->setLeadcampaign(
$leadcampaign, // new leadcampaign entity
$validlead, // leadstatus = valid
$lead, // Lead
$buyer->getCampaign(), // Campaign
$resultoutPost['price'], // price retrieved from the call
$resultoutPost['wslog'] // entity Wslog2
);
// Update campaign numbers
$postaccepted = array(
//'price' => floatval($resultoutPost["price"]),
'price' => $resultoutPost['price'],
'campaign' => $buyer->getCampaign()->getId(),
'pingid' => $resultoutPost['pingid']
);
array_push($allresultspost,$postaccepted);
$postresults[] = array(
'value' => round(($postaccepted['price'] * $commission / 100),2),
'currency' => $project->getCurrency()->getSymbol()
);
$counter++;
}
}
}
}
return $resultoutPost;
}
public function pingfield($fields, $data, $ping)
{
foreach ($fields as $field) {
$fieldname = $field->getName();
if (isset($data[$fieldname])) {
$this->insertpingfield($ping, $field, $data[$fieldname]);
}
}
return 1;
}
public function insertpingfield($ping, $field, $data)
{
$em = $this->getDoctrine()->getManager();
// Insert leadfields
$pingfield = new Pingfield();
$pingfield->setPing($ping);
$pingfield->setField($field);
$pingfield->setValue($data);
$em->persist($pingfield);
$em->flush();
}
public function inboundcalllog(string $header = null, array $data = null, object $entity = null, string $response = null, object $lead = null) { // set and update inbound call logs
$em = $this->getDoctrine()->getManager();
try{
if($entity == null) { // new call received
$entity = new ApiLeadsLogs();
$entity->setUser($this->getUser()); // user that lanched the call
if(isset($data['project'])) {
$project = $this->getDoctrine()->getRepository(Project::class)->findOneById($data["project"]);
$entity->setProject($project); // Insert null if project doesn't exist
}
$entity->setTimestamp(time());
$entity->setHeaders($header);
$entity->setData(json_encode($data));
} else {
$entity->setLead($lead);
if (str_contains($response,'"success":true,') ){
$entity->setSuccess(true);
}else{
$entity->setSuccess(false);
}
$entity->setResponse($response);
}
$em->persist($entity);
$em->flush();
} catch(\Exception $e) {
$entity = new ApiLeadsLogs();
$entity->setUser($this->getUser());
$entity->setTimestamp(time());
$entity->setData("Message: ".$e->getMessage().", File: ".$e->getFile().", Line: ".$e->getLine());
$em->persist($entity);
$em->flush();
return false;
}
return $entity;
}
public function listleadchecks ($lead){
$em = $this->getDoctrine()->getManager();
$listlead = new ListLeadChecks();
$listlead->setLead($lead);
$listlead->setCampaignsconnected($this->campaignsconnected);
$listlead->setDuplicateemail($this->duplicateemail);
$listlead->setDuplicatelephone($this->duplicatelephone);
$listlead->setHoneypot($this->honeypotcheck);
$listlead->setInvalidemail($this->invalidemailcheck);
$listlead->setBlacklisted($this->blacklistedcheck);
$listlead->setMandatoryFields($this->mandatoryfields);
$listlead->setFieldrules($this->fieldrules);
$em->persist($listlead);
$em->flush();
}
public function campaignsconnected($project){
$repository = $this->getDoctrine()->getRepository(Campaign::class);
$query = $repository->createQueryBuilder('c');
$query->addSelect('c.id');
$query->addSelect('c.name');
$query->addSelect('c.priority');
$query->addSelect('s.status');
$query->addSelect('co.name as company');
$query->leftJoin('App:Status', 's', 'WITH', 'c.status = s.id');
$query->leftJoin('App:Company', 'co', 'WITH', 'co.id = c.company');
$query->andWhere(':project MEMBER OF c.project');
$query->setParameter('project', $project->getId());
$query->addOrderBy('c.priority','DESC'); // the higher the better
$query->addOrderBy('c.price','DESC'); // the higher the better
$query = $query->getQuery();
$campaigns = $query->getResult();
$connectedcampaigns = [];
foreach ($campaigns as $campaign){
$arraycampaign = array(
'id' => $campaign["id"],
'name' => $campaign["name"],
'status' => $campaign["status"],
'priority' => $campaign["priority"],
'company' => $campaign["company"]
);
array_push($connectedcampaigns,$arraycampaign);
}
return $connectedcampaigns;
}
public function customFeedback($code,$success,$message,$lead){
$result = array(
'code' => $code,
'success' => $success,
'message' => $message,
'lead id' => $lead
);
return $result;
}
public function checkMandarotyFields($lead, $fields){
$result = "";
foreach ($fields as $field){
if ($field->getMandatory() !== null && $field->getMandatory() !== false){
$fieldvalue = $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(array(
'lead' => $lead,
'field' => $field
)
);
if (!isset($fieldvalue)){
if ($result == ""){
$result = "Missing fields: ".$field->getName();
}else{
$result .= ", ".$field->getName();
}
}
}
}
return $result;
}
public function checkFieldsRules($lead, $fields){
$result = "";
foreach ($fields as $field){
if ($field->getFieldrules() !== null && $field->getFieldrules() !== false && $result == ""){
$fieldvalue = $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(array(
'lead' => $lead,
'field' => $field
)
);
if($field->getFieldrules()->getFieldRulesType()->getId() == 1){//Regular expression
//1 success 0 invalid
$check = preg_match($field->getFieldrules()->getValue(),$fieldvalue->getValue());
if ($check == 0){
$result = "Inserted value is invalid for field: ".$field->getName();
}
}elseif ($field->getFieldrules()->getFieldRulesType()->getId() == 2){//DateFormat
$isItDate = date_create_from_format($field->getFieldrules()->getValue(),$fieldvalue->getValue());
if ($isItDate == false){
$result = "Inserted value is invalid for field: ".$field->getName();
}
}elseif ($field->getFieldrules()->getFieldRulesType()->getId() == 3){//Select
$values = explode(",",$field->getFieldrules()->getValue());
$check = in_array($fieldvalue->getValue(),$values);
//true check success
if ($check == false){
$result = "Invalid value for field: ".$field->getName();
}
}
}
}
return $result;
}
}