src/Controller/ApiController.php line 4503

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Account;
  4. use App\Entity\ApiInboundTraffic;
  5. use App\Entity\ApiLeadsLogs;
  6. use App\Entity\CampaignThankYou;
  7. use App\Entity\ListLeadChecks;
  8. use App\Entity\ProjectFilterLog;
  9. use App\Entity\Wslog2;
  10. use App\Entity\DoiLogs;
  11. use App\Entity\EmailSetUp;
  12. use App\Service\Utilities\EmailService;
  13. use App\Service\CampaignService\CampaignService;
  14. use App\Entity\PageType;
  15. use App\Entity\Ping;
  16. use App\Entity\Pingfield;
  17. use App\Entity\Post;
  18. use App\Entity\ServerToServer;
  19. use App\Entity\ServerToServerLog;
  20. use App\Entity\ThankYou;
  21. use App\Entity\UniqueEmails;
  22. use App\Entity\UniquePhone;
  23. use App\Entity\WslogCallType;
  24. use App\Entity\WslogInboundPing;
  25. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  26. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  27. use Symfony\Component\HttpFoundation\Request;
  28. use Symfony\Component\HttpFoundation\Response;
  29. use App\Entity\Lead;
  30. use App\Entity\Session;
  31. use App\Entity\Campaign;
  32. use App\Entity\Company;
  33. use App\Entity\Project;
  34. use App\Entity\Fieldcampaign;
  35. use App\Entity\Field;
  36. use App\Entity\Leadfield;
  37. use App\Entity\Leadcampaign;
  38. use App\Entity\Ws;
  39. use App\Entity\Wslog;
  40. use App\Entity\Lang;
  41. use App\Entity\Country;
  42. use App\Entity\Leadstatus;
  43. use App\Entity\Hasoffers;
  44. use App\Entity\Filter;
  45. use App\Entity\Filtergroup;
  46. use App\Entity\Filtercampaign;
  47. use App\Entity\Filtercampaigngroup;
  48. use App\Entity\Page;
  49. use App\Entity\Projectmail;
  50. use App\Entity\Campaignfilterlog;
  51. use App\Entity\Header;
  52. use App\Entity\Fraudstatus;
  53. use App\Entity\Antifraud;
  54. use App\Entity\Status;
  55. use Symfony\Component\Form\Extension\Core\Type\TextType;
  56. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  57. use Symfony\Component\Form\Extension\Core\Type\DateType;
  58. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  59. use Symfony\Component\Form\Extension\Core\Type\NumberType;
  60. use Symfony\Component\Form\Extension\Core\Type\FileType;
  61. use Symfony\Component\Form\Extension\Core\Type\RadioType;
  62. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  63. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  64. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  65. use Doctrine\ORM\EntityRepository;
  66. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  67. use stdClass;
  68. use App\Form\Type\CustomFieldcampaignType;
  69. use App\Form\Type\CustomFieldcampaign2Type;
  70. use App\Form\Type\CustomFieldprojectType;
  71. use App\Form\Type\CustomFieldproject2Type;
  72. use App\Form\Type\ProjectType;
  73. use App\Form\Type\MultipleFieldsType;
  74. use Symfony\Component\Validator\Constraints\DateTime;
  75. use App\Controller\AppOpticksController;
  76. use App\Entity\Processtatus;
  77. class ApiController extends AbstractController
  78. {
  79.     private $testlead false;
  80.     private $testwebservice false;
  81.     private $honeypotcheck ;
  82.     private $invalidemailcheck ;
  83.     private $duplicatelephone ;
  84.     private $duplicateemail ;
  85.     private $campaignsconnected ;
  86.     private $blacklistedcheck$mandatoryfields$fieldrules ;
  87.     public function __construct(EmailService $emailServiceCampaignService $campaignService) {
  88.         $this->emailService $emailService;
  89.         $this->campaignService $campaignService;
  90.     }
  91.     public function subscribe(Request $request) {
  92.         // Mapping base Data
  93.         $data $request->request->all();
  94.         $em $this->getDoctrine()->getManager();
  95.         // Set test variable
  96.         $data['test'] = false;
  97.         $testlead false;
  98.         $testwebservice false;
  99.         // Set result array
  100.         $resultin = array(
  101.             'honeypot' => false,
  102.             'inactive' => false,
  103.             'invalidemail' => false,
  104.             'invaliddomain' => false,
  105.             'duplicategen' => false,
  106.             'duplicate' => false,
  107.             'duplicatetracking' => false,
  108.             'invalidtracking' => false,
  109.             'fake' => false,
  110.             'validproject' => false,
  111.             'inserted' => false,
  112.             'novalidproject' => false,
  113.             'api_project' => false,
  114.             'duplicateemailproject' => false,
  115.             'roifail' => false,
  116.             'blacklist' => false,
  117.         );
  118.         $resultout = array(
  119.             'validcampaign' => false,
  120.             'validcustomer' => false
  121.         );
  122.         $revenue 0;
  123.         $sold 0;
  124.         $active $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
  125.         $inboundcalllog $this->inboundcalllog($request->headers$request->request->all()); // create a new log for inbound call
  126.         //Delete after code something to block sources
  127.         if (isset($data['source'])) {
  128.             if ($data["source"] == "2871"){
  129.                 
  130.                 $resultin['novalidproject'] = true;
  131.                 $result $this->feedback($resultin$resultout);
  132.                 // Update Apileadlogs
  133.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result));
  134.                 return $this->json($result);
  135.             }
  136.         }//
  137.         // Set project variable
  138.         if (isset($data['project'])) {
  139.             $project_id $data['project'];
  140.         } else { // No project set in the data payload
  141.             $resultin['novalidproject'] = true;
  142.             $result $this->feedback($resultin$resultout);
  143.             // Update Apileadlogs
  144.             $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result));
  145.             return $this->json($result);
  146.         }
  147.         // Check if project exist and it's active. If not return
  148.         $project $this->getDoctrine()->getRepository(Project::class)->findOneById($project_id);
  149.         if ($this->getUser()->getId() == 9){
  150.             dd("oiuhasd");
  151.         }
  152.         if ($project == null) { // No project found
  153.             $resultin['api_project'] = true;
  154.             $result $this->feedback($resultin$resultout);
  155.             // Update Apileadlogs
  156.             $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result));
  157.             return $this->json($result);
  158.         } elseif($project->getStatus()->getId() == 9) { // project in test status
  159.             //affiliates
  160.             if ($this->getUser()->getId() !== && $this->getUser()->getProject()->contains($project) !== true) {
  161.                 $resultin['api_project'] = true;
  162.                 $result $this->feedback($resultin$resultout);
  163.                 // Update Apileadlogs
  164.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result));
  165.                 return $this->json($result);
  166.             }
  167.             $test $this->getDoctrine()->getRepository(Status::class)->findOneById(9);
  168.             $resultin['validproject'] = true;
  169.             $resultin['inserted'] = true;
  170.             $resultin['validcampaign'] = true;
  171.             $resultout['validcampaign'] = true;
  172.             $resultout['validcustomer'] = true;
  173.             $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(18);
  174.             $fields $this->getDoctrine()->getRepository(Field::class)->findBy(
  175.                 array(
  176.                     'project' => $project,
  177.                     'status' => $active
  178.                 )
  179.             );
  180.             // Notify test lead to tracking platform
  181.             try {
  182.                 $lead $this->insertlead($data$project$lead_status);
  183.                 $leadfield $this->leadfield($fields$data$lead);
  184.                 /*$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';
  185.                 $ch = curl_init();
  186.                 curl_setopt($ch, CURLOPT_URL, $url);
  187.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  188.                 $result = curl_exec($ch);
  189.                 curl_close($ch);*/
  190.             } catch (\Exception $e){
  191.                 $result =  array(
  192.                     'code' => 404,
  193.                     'success' => false,
  194.                     'message' => 'Problem inserting the lead',
  195.                     'lead id' => $lead->getId()
  196.                 );
  197.                 return $this->json($result);
  198.             }
  199.             //checkMandarotyFields
  200.             $mandatorycheck $this->checkMandarotyFields($lead,$fields);
  201.             if ($mandatorycheck !== ''){
  202.                 $result $this->customFeedback(404,false,$mandatorycheck,$lead->getId());
  203.                 //return no all mandatory fields were filled
  204.                 $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20); // Filter project fail
  205.                 $lead->setStatus($lead_status);
  206.                 $em->persist($lead);
  207.                 $em->flush();
  208.                 $this->mandatoryfields false;
  209.                 $this->listleadchecks($lead);
  210.                 // Update Apileadlogs
  211.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  212.                 return $this->json($result); // End of process
  213.             }
  214.             $this->mandatoryfields true;
  215.             //endchecheckingMandatoryFields
  216.             try {
  217.                 $checkfieldsrules $this->checkFieldsRules($lead,$fields);
  218.                 if ($checkfieldsrules != ""){
  219.                     $result $this->customFeedback(404,false,$checkfieldsrules,$lead->getId());
  220.                     //return rules fields no succeded
  221.                     $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20); // Filter project fail
  222.                     $lead->setStatus($lead_status);
  223.                     $em->persist($lead);
  224.                     $em->flush();
  225.                     $this->fieldrules false;
  226.                     $this->listleadchecks($lead);
  227.                     // Update Apileadlogs
  228.                     $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  229.                     return $this->json($result); // End of process
  230.                 }
  231.             }catch (\Exception $e){
  232.             }
  233.             $this->fieldrules true;
  234.             $price '0';
  235.             if ($this->getUser()->getId() !== && $this->getUser()->getProject()->contains($project) !== true) {
  236.                 $result =  array(
  237.                     'code' => 404,
  238.                     'success' => false,
  239.                     'message' => 'Contact us to change your permissions',
  240.                     'lead id' => $lead->getId()
  241.                 );
  242.                 $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20);
  243.                 $lead->setStatus($lead_status);
  244.                 $em->persist($lead);
  245.                 $em->flush();
  246.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  247.                 return $this->json($result);
  248.             }
  249.             if (($project->getTracking() !== null && $project->getTracking()->getId() == '1') || $project->getProjectEverflow() == null){
  250.                 $result =  array(
  251.                     'code' => 404,
  252.                     'success' => false,
  253.                     'message' => 'Contact us to change tracking set up',
  254.                     'lead_id' => $lead->getId()
  255.                 );
  256.                 $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20);
  257.                 $lead->setStatus($lead_status);
  258.                 $em->persist($lead);
  259.                 $em->flush();
  260.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  261.                 return $this->json($result);
  262.             } elseif ($project->getProjectEverflow() != null){
  263.                 if ($project->getProjectEverflow() !== null) { 
  264.                     //if project has everflow connection(API projects mainly) we set up source and offer
  265.                     $data["source"] = (string)$project->getProjectEverflow()->getSource();
  266.                     $data["offer"] = (string)$project->getProjectEverflow()->getOffer();
  267.                 }
  268.                 if ($lead->getProject()->getRevenueShare() == true){
  269.                     if (isset($data["clickid"])){
  270.                         $tracking $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId(),"price"=>$price))->getContent();
  271.                     }elseif(isset($data["source"]) && isset($data["offer"])){
  272.                         $tracking $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId(),"price"=>$price))->getContent();
  273.                     }else{
  274.                         $tracking false;
  275.                     }
  276.                 }else{
  277.                     if (isset($data["clickid"])){
  278.                         $tracking $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
  279.                     }elseif(isset($data["source"]) && isset($data["offer"])){
  280.                         $tracking $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
  281.                     }else{
  282.                         $tracking false;
  283.                     }
  284.                 }
  285.                 if ($tracking == "true"){ // Tracking process accepted
  286.                     // Set up cost
  287.                     try {
  288.                         if ($project->getRevenueShare() == true){ // Project on Revenue share: the cost is calculated internally
  289.                             if ($project->getCommissions() == 0){
  290.                                 $commission 1;
  291.                             }else{
  292.                                 $commission $project->getCommissions();
  293.                             }
  294.                             $cost = ($price*$commission)/100;
  295.                         }else{ // Project on fixed CPL: the cost is taken from the tracking system setup for each publisher
  296.                             $cost $this->forward('App\Controller\EverFlowController::retrieveCost', array("offer" => $data["offer"], "affid" => $data["source"]))->getContent();
  297.                             if (json_decode($cost)->cost == && $project->getProjectEverflow() == null){
  298.                                 $cost $this->forward('App\Controller\EverFlowController::retrieveCostOffer', array("offer" => $data["offer"]))->getContent();
  299.                             }else{
  300.                                 $cost = array(
  301.                                     "cost" => 0
  302.                                 );
  303.                                 $cost=json_encode($cost);
  304.                             }
  305.                             $cost json_decode($cost)->cost;
  306.                         }
  307.                     }catch (\Exception $e){
  308.                         $cost 0;
  309.                     }
  310.                     $lead->setCost(floatval($cost));
  311.                 } else { // Tracking process rejected
  312.                     $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6);
  313.                     $lead->setStatus($lead_status); // duplicate lead
  314.                     $resultin['invalidtracking'] = true;
  315.                 }
  316.             }
  317.             $result $this->feedback($resultin$resultout$lead$price);
  318.             if ($project->getStatus()->getId() == 9) {
  319.                 if ($result["message"] == "valid user") {
  320.                     $result["message"] = "valid test";
  321.                 }
  322.             }
  323.             // Update Apileadlogs
  324.             $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  325.             return $this->json($result); // End of process
  326.         } elseif($project->getStatus()->getId() !== 1) { // project not active
  327.             $resultin['api_project'] = true;
  328.             $result $this->feedback($resultin$resultout);
  329.             // Update Apileadlogs
  330.             $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result));
  331.             return $this->json($result);
  332.         } else {
  333.             // Check if the user api is allowed to insert lead in this project
  334.             if ($this->getUser()->getId() !== && $this->getUser()->getProject()->contains($project) !== true) {
  335.                 $resultin['api_project'] = true;
  336.                 $result $this->feedback($resultin$resultout);
  337.                 // Update Apileadlogs
  338.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result));
  339.                 return $this->json($result);
  340.             }
  341.         }
  342.         // Set email variable
  343.         if (isset($data['email'])) {
  344.             $email strtolower(trim($data['email']));
  345.         } else {
  346.             $email null;
  347.         }
  348.         // Set test variables
  349.         try {
  350.             if (isset($email)){
  351.                 if (str_contains($email'@loudingads.com') == true ) { // lead sent to tracking but not sent to campaigns
  352.                     $data['test'] = true;
  353.                     $testlead true;
  354.                     $this->setTestlead(true);
  355.                 }elseif (str_contains($email'@loudingest.com') == true) { // lead sent only to campaigns in test status
  356.                     $data['test'] = true;
  357.                     $testwebservice true;
  358.                     $this->setTestwebservice(true);
  359.                 }
  360.             }
  361.         } catch (\Exception $e) {
  362.         }
  363.         // Check if user is a bot
  364.         if (isset($data['honeypot'])){
  365.             if ($data['honeypot'] !== null && $data['honeypot'] !== ''){
  366.                 $resultin['validproject'] = true;
  367.                 $resultin['honeypot'] = true;
  368.                 $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(19); // bot
  369.                 $lead $this->insertlead($data$project$lead_status);
  370.                 $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  371.                 $this->honeypotcheck false ;
  372.                 $this->listleadchecks($lead);
  373.                 // Update Apileadlogs
  374.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  375.                 return $this->json($result); // End of process
  376.             }
  377.         }
  378.         $this->honeypotcheck true ;
  379.         // Check if email is valid
  380.         $emailcheck $this->emailcheck($email);
  381.         if ($emailcheck == || $emailcheck == 3) {
  382.             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) {
  383.                 if ($emailcheck == 2) {
  384.                     $resultin['invalidemail'] = true;
  385.                     $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(9); // invalid email
  386.                 }elseif ($emailcheck == 3) {
  387.                     $resultin['invaliddomain'] = true;
  388.                     $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(10); // invalid domain dns
  389.                 }
  390.                 $this->invalidemailcheck false;
  391.                 $lead $this->insertlead($data$project$lead_status);
  392.                 $this->listleadchecks($lead);
  393.                 $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  394.                 // Update Apileadlogs
  395.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  396.                 return $this->json($result); // End of process
  397.             }
  398.         }
  399.         $this->invalidemailcheck true;
  400.         // Check blacklist
  401.         foreach ($project->getBlackLists() as $blacklist){
  402.             if ($blacklist->getStatus()->getId() == 1){
  403.                 $conn $em->getConnection();
  404.                 $query 'select * from blacklist_' .$blacklist->getId(). ' where email=? ';
  405.                 $stmt $conn->prepare($query);
  406.                 if ($blacklist->getType() == 'md5'){
  407.                     $stmt->bindValue(1md5($email), 'string');
  408.                 }else{
  409.                     $stmt->bindValue(1hash'SHA256'$email), 'string');
  410.                 }
  411.                 $stmt->execute();
  412.                 if (sizeof($stmt->fetchAll()) > 0) { // user is in blacklist
  413.                     $resultin['blacklist'] = true;
  414.                     $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(17); // black list
  415.                     $lead $this->insertlead($data$project$lead_status);
  416.                     $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  417.                     $this->blacklistedcheck false;
  418.                     $this->listleadchecks($lead);
  419.                     // Update Apileadlogs
  420.                     $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  421.                     return $this->json($result); // End of process
  422.                 }
  423.             }
  424.         }
  425.             $this->blacklistedcheck true;
  426.         // Check if email is already registered in db
  427.         $uniqueemail $this->getDoctrine()->getRepository(UniqueEmails::class)->findByEmail($email);
  428.         if (count($uniqueemail) > 0) { // duplicate in the system. the lead can still be passed to other products
  429.             // Check if email is already registered in the project
  430.             $leadproject $this->getDoctrine()->getRepository(Lead::class)->findBy(
  431.                 array(
  432.                     'email' => $email,
  433.                     'project' => $project
  434.                 )
  435.             );
  436.             if (count($leadproject) > 0) {
  437.                 $resultin['duplicateemailproject'] = true;
  438.                 $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6); // duplicate for this project
  439.                 $lead $this->insertlead($data$project$lead_status);
  440.                 // Not passed to customers
  441.                 $fields $this->getDoctrine()->getRepository(Field::class)->findBy(
  442.                     array(
  443.                         'project' => $project,
  444.                         'status' => $active
  445.                     )
  446.                 );
  447.                 $leadfield $this->leadfield($fields$data$lead);
  448.                 $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  449.                 $this->duplicateemail false;
  450.                 $this->listleadchecks($lead);
  451.                 // Update Apileadlogs
  452.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  453.                 return $this->json($result); // End of process
  454.             }
  455.             $resultin['duplicategen'] = true;
  456.             $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(14);
  457.             // 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
  458.             /*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 ) {*/
  459.             // If the lead belongs to the same project label it's duplicate and won't be passed to the customers
  460.             $repository $this->getDoctrine()->getRepository(Lead::class);
  461.             $query $repository->createQueryBuilder('l');
  462.             //$query->addSelect('count(l.id)');
  463.             $query->leftJoin('App:Project''p''WITH''l.project = p.id');
  464.             $query->leftJoin('App:LabelProject''lb''WITH''p.label = lb.id');
  465.             $query->andWhere('l.email = :email');
  466.             $query->andWhere('lb.id = :label');
  467.             $query->setParameter('email'$email);
  468.             $query->setParameter('label'$project->getLabel()->getId());
  469.             $query $query->getQuery();
  470.             $label_duplicate $query->getResult();
  471.             if(count($label_duplicate) > 0) { // duplicate for the same product the lead won't be passed
  472.                 $resultin['duplicateemailproject'] = true;
  473.                 $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6); // duplicate for this project
  474.                 $lead $this->insertlead($data$project$lead_status);
  475.                 // Not passed to customers
  476.                 $fields $this->getDoctrine()->getRepository(Field::class)->findBy(
  477.                     array(
  478.                         'project' => $project,
  479.                         'status' => $active
  480.                     )
  481.                 );
  482.                 $leadfield $this->leadfield($fields$data$lead);
  483.                 $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  484.                 $this->duplicateemail false;
  485.                 $this->listleadchecks($lead);
  486.                 // Update Apileadlogs
  487.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  488.                 return $this->json($result); // End of process
  489.             }
  490.         } else { // not duplicate
  491.             $uniqueemail = new UniqueEmails();
  492.             $uniqueemail->setEmail($email);
  493.             $em->persist($uniqueemail);
  494.             $em->flush();
  495.         }
  496.         $this->duplicateemail true;
  497.         if (isset($data['phone'])) {
  498.             $phone strval(str_replace(' ','',$data['phone']));
  499.         } else {
  500.             $phone null;
  501.         }
  502.         //check blacklisted phone
  503.         try{
  504.             if ($this->testlead == false && $this->testwebservice == false){
  505.             foreach ($project->getPhoneBlackLists() as $phoneblacklist){
  506.                 if ($phoneblacklist->getStatus()->getId() == 1){
  507.                     $conn $em->getConnection();
  508.                     $query 'select * from phoneblacklist_' .$phoneblacklist->getId(). ' where phone=? ';
  509.                     $stmt $conn->prepare($query);
  510.                     if ($blacklist->getType() == 'md5'){
  511.                         $stmt->bindValue(1md5($phone), 'string');
  512.                     }else{
  513.                         $stmt->bindValue(1hash'SHA256'$phone), 'string');
  514.                     }
  515.                     $stmt->execute();
  516.                     if (sizeof($stmt->fetchAll()) > 0) { // user is in blacklist
  517.                         $resultin['blacklist'] = true;
  518.                         $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(17); // black list
  519.                         $lead $this->insertlead($data$project$lead_status);
  520.                         $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  521.                         $this->blacklistedcheck false;
  522.                         $this->listleadchecks($lead);
  523.                         // Update Apileadlogs
  524.                         $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  525.                         return $this->json($result); // End of process
  526.                     }
  527.                     $this->blacklistedcheck true;
  528.                 }
  529.             }
  530.             }
  531.         } catch(\Exception $e) {
  532.             //if the code inside the try doesnt work will keep the flow
  533.         }
  534.         // Check if phone is already registered in db
  535.         if($this->testlead == false && $this->testwebservice == false) { // check double phone only if it's not a test
  536.             $uniquephone $this->getDoctrine()->getRepository(UniquePhone::class)->findByPhone($phone);
  537.             if (count($uniquephone) > 0) { // duplicate in the system. the lead can still be passed to other products
  538.                 // Check if phone is already registered in the project
  539.                 $leadproject $this->getDoctrine()->getRepository(Lead::class)->findBy(
  540.                     array(
  541.                         'phone' => $phone,
  542.                         'project' => $project
  543.                     )
  544.                 );
  545.                 if (count($leadproject) > 0) {
  546.                     $resultin['duplicateemailproject'] = true;
  547.                     $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(15); // duplicate for this project
  548.                     $lead $this->insertlead($data$project$lead_status);
  549.                     // Not passed to customers
  550.                     $fields $this->getDoctrine()->getRepository(Field::class)->findBy(
  551.                         array(
  552.                             'project' => $project,
  553.                             'status' => $active
  554.                         )
  555.                     );
  556.                     $leadfield $this->leadfield($fields$data$lead);
  557.                     $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  558.                     $this->duplicatelephone false;
  559.                     $this->listleadchecks($lead);
  560.                     // Update Apileadlogs
  561.                     $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  562.                     return $this->json($result); // End of process
  563.                 }
  564.                 $resultin['duplicategen'] = true;
  565.                 $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(14);
  566.                 // If the lead belongs to the same project label it's duplicate and won't be passed to the customers
  567.                 $repository $this->getDoctrine()->getRepository(Lead::class);
  568.                 $query $repository->createQueryBuilder('l');
  569.                 //$query->addSelect('count(l.id)');
  570.                 $query->leftJoin('App:Project''p''WITH''l.project = p.id');
  571.                 $query->leftJoin('App:LabelProject''lb''WITH''p.label = lb.id');
  572.                 $query->andWhere('l.phone = :phone');
  573.                 $query->andWhere('lb.id = :label');
  574.                 $query->setParameter('phone'$phone);
  575.                 $query->setParameter('label'$project->getLabel()->getId());
  576.                 $query $query->getQuery();
  577.                 $label_duplicate $query->getResult();
  578.                 if(count($label_duplicate) > 0) { // duplicate for the same product the lead won't be passed
  579.                     $resultin['duplicateemailproject'] = true;
  580.                     $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6); // duplicate for this project
  581.                     $lead $this->insertlead($data$project$lead_status);
  582.                     // Not passed to customers
  583.                     $fields $this->getDoctrine()->getRepository(Field::class)->findBy(
  584.                         array(
  585.                             'project' => $project,
  586.                             'status' => $active
  587.                         )
  588.                     );
  589.                     $leadfield $this->leadfield($fields$data$lead);
  590.                     $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  591.                     // Update Apileadlogs
  592.                     $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  593.                     $this->listleadchecks($lead);
  594.                     return $this->json($result); // End of process
  595.                 }
  596.             } else { // not duplicate
  597.                 $uniquephone = new UniquePhone();
  598.                 $uniquephone->setPhone($phone);
  599.                 $em->persist($uniquephone);
  600.                 $em->flush();
  601.             }
  602.         }
  603.         $this->duplicatelephone true;
  604.         // Insert lead
  605.         $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(1); // active email
  606.         $lead $this->insertlead($data$project$lead_status);
  607.        /* if (isset($data["tokenrecaptcha"])){
  608.             $this->forward('App\Controller\RecaptchaController::saveAPIResponse', array('data' => $data, 'lead' =>$lead));
  609.         }*/
  610.         if ($lead == null) { // If lead insertion fails
  611.             // Not passed to customers
  612.             $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  613.             $this->listleadchecks($lead);
  614.             // Update Apileadlogs
  615.             $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  616.             return $this->json($result); // End of process
  617.         } else {
  618.             $resultin['inserted'] = true;
  619.         }
  620.         // Validate and set custom fields
  621.         // Get fields of the project
  622.         $fields $this->getDoctrine()->getRepository(Field::class)->findBy(
  623.             array(
  624.                 'project' => $project,
  625.                 'status' => $active
  626.             )
  627.         );
  628.         // Insert custom field
  629.         $leadfield $this->leadfield($fields$data$lead);
  630. //checkMandarotyFields
  631.         $mandatorycheck $this->checkMandarotyFields($lead,$fields);
  632.         if ($mandatorycheck != ""){
  633.             $result $this->customFeedback(404,false,$mandatorycheck,$lead->getId());
  634.             //return no all mandatory fields were filled
  635.             $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20); // Filter project fail
  636.             $lead->setStatus($lead_status);
  637.             $em->persist($lead);
  638.             $em->flush();
  639.             $this->mandatoryfields false;
  640.             $this->listleadchecks($lead);
  641.             // Update Apileadlogs
  642.             $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  643.             return $this->json($result); // End of process
  644.         }
  645.         $this->mandatoryfields true;
  646.         //endchecheckingMandatoryFields
  647.         try {
  648.             $checkfieldsrules $this->checkFieldsRules($lead,$fields);
  649.             if ($checkfieldsrules != ""){
  650.                 $result $this->customFeedback(404,false,$checkfieldsrules,$lead->getId());
  651.                 //return no all mandatory fields were filled
  652.                 $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(20); // Filter project fail
  653.                 $lead->setStatus($lead_status);
  654.                 $em->persist($lead);
  655.                 $em->flush();
  656.                 $this->fieldrules false;
  657.                 $this->listleadchecks($lead);
  658.                 // Update Apileadlogs
  659.                 $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  660.                 return $this->json($result); // End of process
  661.             }
  662.         }catch (\Exception $e){
  663.         }
  664.         $this->fieldrules true;
  665.         // DOI
  666.         if ($project->getDoi() !== && $project->getDoi() !== null ){
  667.             $laststatus $lead->getStatus();
  668.             $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(18);
  669.             if (($lead->getStatus()->getId()!=1  && $lead->getStatus()->getId()!=2) || str_contains($data['email'], '@test.com') || $this->testlead == true){
  670.                 $lead->setStatus($lead_status);
  671.             }
  672.             if($lead->getStatus()->getId()==1  || $lead->getStatus()->getId()==|| $lead->getStatus()->getId()==18){
  673.                 $setUps $this->getDoctrine()->getRepository(EmailSetUp::class)->findby(
  674.                     array(
  675.                         'project' => $project->getId(),
  676.                         'status' => 1
  677.                     )
  678.                 );
  679.                 /*if (str_contains($data['email'], '@loudingads.com') == true){
  680.                     dd("holi");
  681.                 }*/
  682.                 if (count($setUps) != ){
  683.                     $setUp $setUps[count($setUps)-1];
  684.                     /* if (str_contains($lead->getEmail(), '@test.com') == true || str_contains($lead->getEmail(),'@loudingads.com' == true)){
  685.                          $emailchanged =  $data['email'];
  686.                          $data['email'] = "lennard.loudingads@gmail.com";
  687.                          $lead->setEmail("lennard.loudingads@gmail.com");
  688.                          $changeemail=true;
  689.                      }*/
  690.                     $doidata['url'] = $data['referral'];
  691.                     $doidata["version"] =substr($doidata['url'],0,(stripos($doidata['url'],"/v")+4));
  692.                     $doidata['lead'] = $lead->getId();
  693.                     $doidata['encryptedlead'] = openssl_encrypt(
  694.                         $lead->getId(),
  695.                         "aes128",
  696.                         "vLjow7178",
  697.                         0,
  698.                         $iv="7983248923794221" );
  699.                     $doidata['sendto'] = $lead->getEmail();
  700.                     //if ( ($project->getId() !=23 ) ||($project->getId()==23 && (str_contains($data['email'], '@test.com') == true || str_contains($data['email'], 'loudingads') == true))) {
  701.                     switch ($setUp->getEmailsetuptype()->getId()) {
  702.                         case 1//
  703.                             $result $this->forward('App\Controller\DoiServiceController::SMTP', array('emailsetupid' => $setUp->getId(), "doidata" => $doidata))->getContent();
  704.                             break;
  705.                     }
  706.                 }
  707.             }
  708.             $lead->setStatus($laststatus);
  709.         }
  710.         // Check if custom field are valid with Filter project
  711.         $resultin['validproject'] = $this->checkfilter($lead);
  712.         if ($resultin['validproject'] == false) { // checkfilter is false
  713.             $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(12); // Filter project fail
  714.             $lead->setStatus($lead_status);
  715.             $em->persist($lead);
  716.             $em->flush();
  717.             $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  718.             // Update Apileadlogs
  719.             $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  720.             $this->listleadchecks($lead);
  721.             return $this->json($result); // End of process
  722.         }
  723.         // Set test mode for antifraud
  724.         try {
  725.             $antifraud $this->antifraud($lead,$data); // return fraud status
  726.         } catch(\Exception $e) {
  727.         }
  728.         // Check all the Campaigns available for this Project
  729.         $repository $this->getDoctrine()->getRepository(Campaign::class);
  730.         $query $repository->createQueryBuilder('c');
  731.         $query->addSelect('c');
  732.         $query->leftJoin('App:Status''s''WITH''c.status = s.id');
  733.         $query->leftJoin('App:LeadVerification''lv''WITH''c.sending = lv.id');
  734.         $query->leftJoin('App:sensibility''sy''WITH''c.sensibility = sy.id');
  735.         $query->andWhere(':project MEMBER OF c.project');
  736.         $query->setParameter('project'$project->getId());
  737.         $query->andWhere('s.id = :status'); // Exclude inactive campaign
  738.         if (str_contains($lead->getEmail(), '@loudingest.com') == true){ // Get only Test campaign
  739.             $query->setParameter('status'9);
  740.         }else{
  741.             $query->setParameter('status'1); // Get only active campaign
  742.         }
  743.         $query->andWhere('lv.id = :verification');
  744.         $query->setParameter('verification'1); // soi or doi
  745.         // Antifraud exclusion
  746.         if( $this->testwebservice != true && $this->testlead != true && isset($antifraud) && $antifraud !== null ) { // Apply Sensibility only if the Lead has an antifraud check
  747.             if($antifraud->getStatus()->getId() == 2) { // suspicious, not for high sensibility
  748.                 $query->andWhere('sy.id != :sensibility');
  749.                 $query->setParameter('sensibility'1);
  750.             } elseif($antifraud->getStatus()->getId() == 4) { // undefined, only for low sensibility campaigns
  751.                 $query->andWhere('sy.id = :sensibility');
  752.                 $query->setParameter('sensibility'3);
  753.             } elseif($antifraud->getStatus()->getId() == 3) { // invalid, only for low sensibility campaigns
  754.                 $query->andWhere('sy.id = :sensibility');
  755.                 $query->setParameter('sensibility'3);
  756.             }
  757.         }
  758.         //$query->orderBy('c.id','ASC');
  759.         $query->addOrderBy('c.priority','DESC'); // the higher the better
  760.         $query->addOrderBy('c.price','DESC'); // the higher the better
  761.         $query $query->getQuery();
  762.         $campaigns $query->getResult();
  763.        /*if (str_contains($lead->getEmail(), '@loudingest.com') == true){
  764. dd(count($campaigns),$project,$lead->getEmail(),$this->testwebservice);
  765.         }*/
  766.         $validate 1;
  767.         /*if (str_contains($lead->getEmail(), '@loudingest.com') == true){
  768.             $campaigns = $this->getDoctrine()->getRepository(Campaign::class)->findOneById(381);
  769.         }*/
  770.         $this->campaignsconnected $this->campaignsconnected($lead->getProject());
  771. //$this->setTestlead(false);
  772.         if (count($campaigns) == && $this->testlead !== true) { // No Campaign available and no test email
  773.             $resultout null;
  774.             $revenue 0;
  775.             $sold 0;
  776.             $resultin['roifail'] = true;
  777.             $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(16); // roi fail
  778.             $lead->setStatus($lead_status); // roi not reached
  779.             $em->persist($lead);
  780.             $em->flush();
  781.             $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  782.             // Update Apileadlogs
  783.             $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  784.             $this->listleadchecks($lead);
  785.             return $this->json($result); // End of process
  786.         } else {
  787.             if ($this->testlead !== true) { // Not test email
  788.                 // Export to campaign
  789.                 // If the project is pingpost (2)
  790.                 if ( $project->getProjectType()->getId()  == && ( $project->getId() == 176  || $project->getId() == 100 || $project->getId() == 81 || $project->getId() == 139)) {
  791.                     //new function for ping creation ping etc etc
  792.                     //delete after
  793.                    /*     $query = $repository->createQueryBuilder('c');
  794.                         $query->addSelect('c');
  795.                         $query->leftJoin('App:Status', 's', 'WITH', 'c.status = s.id');
  796.                         $query->leftJoin('App:LeadVerification', 'lv', 'WITH', 'c.sending = lv.id');
  797.                         $query->leftJoin('App:sensibility', 'sy', 'WITH', 'c.sensibility = sy.id');
  798.                         $query->andWhere(':project MEMBER OF c.project');
  799.                         $query->setParameter('project', $project->getId());
  800.                         $query->andWhere('s.id = :status'); // Exclude inactive campaign
  801.                             $query->setParameter('status', 9);
  802.                     $query = $query->getQuery();
  803.                     $campaigns = $query->getResult();*/
  804.                             //delete before this point
  805.                     $process_active $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(1);
  806.                     $apiinboundtraffic $this->setApiInboundTraffic($request); // register inbound call status active
  807.                     $apiinboundtraffic->setProject($project);
  808.                     $ping $this->insertping($data$project$process_active$apiinboundtraffic);
  809.                     $fieldsping $this->getDoctrine()->getRepository(Field::class)->findBy(
  810.                         array(
  811.                             'project' => $project,
  812.                             'status' => $active
  813.                         )
  814.                     );
  815.                     try {
  816.                         $this->pingfield($fieldsping$data$ping); // register ping custom fields
  817.                     } catch(\Exception $e) {
  818.                         $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(16);
  819.                         $lead->setStatus($lead_status);
  820.                         $resultin['pingsrejected'] = true;
  821.                         $em->persist($lead);
  822.                         $em->flush();
  823.                         $result $this->clientfeedback($resultin,$apiinboundtraffic,$ping,$price 0);
  824.                         return $this->json($result);
  825.                     }
  826.                     $singlesell $this->sellping($lead,$project,$campaigns,$this->testwebservice,$ping,$apiinboundtraffic);
  827.                     if (isset($singlesell["success"]) && $singlesell["success"] == true) {
  828.                         $postsinglesell $this->sellpost($project,$data,$apiinboundtraffic,$ping,$lead);
  829.                         if (count($postsinglesell)>0) {
  830.                             if ($postsinglesell["check"] == 1) {
  831.                                 $resultout['revenue'] = $postsinglesell["price"];
  832.                                 $resultout['sold'] = 1;
  833.                                 $resultout['validcampaign'] = true;
  834.                                 $resultout['validcustomer'] = true;
  835.                             }else{
  836.                                 $resultout['revenue'] = 0;
  837.                                 $resultout['sold'] = 0;
  838.                                 $resultout['validcampaign'] = true;
  839.                                 $resultout['validcustomer'] = false;
  840.                             }
  841.                         } else {
  842.                             $resultin['leadrejected'] = true;
  843.                             $result $this->clientfeedback($resultin,$apiinboundtraffic,$lead);
  844.                             $this->listleadchecks($lead);
  845.                             return $this->json($result);
  846.                         }
  847.                     } else {
  848.                         $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(16);
  849.                         $lead->setStatus($lead_status);
  850.                         $resultin['pingsrejected'] = true;
  851.                         $em->persist($lead);
  852.                         $em->flush();
  853.                         $this->listleadchecks($lead);
  854.                         $result $this->clientfeedback($resultin,$apiinboundtraffic,$ping,$price 0);
  855.                         return $this->json($result);
  856.                     }
  857.                 } else { // Direct Post Project
  858.                     $resultout $this->export($lead$project$campaigns);
  859.                 }
  860.                 $revenue $resultout['revenue'];
  861.                 $sold $resultout['sold'];
  862.                 $lead->setRevenue($revenue);
  863.                 if ($lead->getRevenue() < $project->getRoi() && !$this->testwebservice) { // Check the ROI
  864.                     $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(16); // roi fail
  865.                     $lead->setStatus($lead_status); // roi not reached
  866.                     $resultin['roifail'] = true;
  867.                     $em->persist($lead);
  868.                     $em->flush();
  869.                     $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  870.                     // Update Apileadlogs
  871.                     $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  872.                     $this->listleadchecks($lead);
  873.                     return $this->json($result); // End of process
  874.                 }
  875.                 $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // valid lead
  876.                 $lead->setStatus($lead_status); // roi reached
  877.                 $price null// the value we user to calculate the return to the publisher with his commission
  878.                 if ($lead->getProject()->getRevenueShare() == true) {
  879.                     $leadscampaigns $this->getDoctrine()->getRepository(Leadcampaign::class)->findBy(array(
  880.                         'lead' => $lead->getId(),
  881.                     ));
  882.                     $prices=[];
  883.                     foreach ($leadscampaigns as $leadcampaign) {
  884.                         if ($leadcampaign->getRevenue() !== 0) {
  885.                             array_push($prices,$leadcampaign->getRevenue());
  886.                         }
  887.                     }
  888.                     $typerevenue $lead->getProject()->getTypeRevenueShare();
  889.                     if ($typerevenue == "lowest") {
  890.                         $price min($prices);
  891.                     } elseif ($typerevenue == "average") {
  892.                         $price array_sum($prices)/count($prices);
  893.                     } elseif ($typerevenue == "highest") {
  894.                         $price max($prices);
  895.                     } elseif ($typerevenue == "roi") {
  896.                         $price $project->getRoi();
  897.                     } else{
  898.                         $price 0;
  899.                     }
  900.                 }
  901.                 // Tracking and cost
  902.                 if ($project->getAppTracking() !== null && $project->getAppTracking()->getId() == 3) { // Everflow
  903.                     if (isset($resultin['duplicategen']) && !$resultin['duplicategen'] == true){
  904.                     if ($project->getProjectEverflow() !== null) { // hardcoded offer and source for API Project
  905.                         //if project has everflow connection(API projects mainly) we set up source and offer
  906.                         $data["source"] = (string)$project->getProjectEverflow()->getSource();
  907.                         $data["offer"] = (string)$project->getProjectEverflow()->getOffer();
  908.                     }
  909.                     if ($lead->getProject()->getRevenueShare() == true) { // Revenue share
  910.                         $price $lead->getRevenue();
  911.                         if (isset($data["clickid"])) {
  912.                             $tracking $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId(),"price"=>$price))->getContent();
  913.                         } elseif (isset($data["source"]) && isset($data["offer"])) {
  914.                             $tracking $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId(),"price"=>$price))->getContent();
  915.                         } else {
  916.                             $tracking false;
  917.                         }
  918.                     } else { // Fixed CPL
  919.                         if (isset($data["clickid"])) {
  920.                             $tracking $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
  921.                         } elseif (isset($data["source"]) && isset($data["offer"])) {
  922.                             $tracking $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
  923.                         } else {
  924.                             $tracking false;
  925.                         }
  926.                     }
  927.                     if ($tracking == 'true') { // The tracking system accepts the conversion
  928.                         try {
  929.                             if ($project->getRevenueShare() == true) { // Project on Revenue share: cost calculated by the system
  930.                                 if ($project->getCommissions() == 0){
  931.                                     $commission 1;
  932.                                 } else {
  933.                                     $commission $project->getCommissions();
  934.                                 }
  935.                                 $cost = ($price*$commission)/100;
  936.                             } else { // Project on fixed CPL: cost taken from the tracking system
  937.                                 $cost $this->forward('App\Controller\EverFlowController::retrieveCost', array('offer' => $data['offer'], 'affid' => $data['source']))->getContent();
  938.                                 if (json_decode($cost)->cost == && $project->getProjectEverflow() == null) { // if there's no specific cost associated to the publisher in Everflow
  939.                                     $cost $this->forward('App\Controller\EverFlowController::retrieveCostOffer', array('offer' => $data['offer']))->getContent();
  940.                                     $cost json_decode($cost)->cost;
  941.                                 } else {
  942.                                     $cost json_decode($cost)->cost;
  943.                                 }
  944.                             }
  945.                         } catch (\Exception $e){
  946.                             $cost 0;
  947.                         }
  948.                         $lead->setCost(floatval($cost));
  949.                     } else { // The tracking system doesn't accept the conversion
  950.                         $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6);
  951.                         $lead->setStatus($lead_status); // duplicate lead
  952.                         $resultin['invalidtracking'] = true;
  953.                     }
  954.                     }
  955.                 } elseif ($lead->getHs() !== null) { // Only if the campaign is tracked in HasOffers
  956.                     $tracking $this->hasoffertrk($lead$data);
  957.                     if ($tracking !== null) {
  958.                         if (isset($tracking->response->data->payout)) {
  959.                             $cost $tracking->response->data->payout;
  960.                             if (isset($tracking->response->data->price)) {
  961.                                 $cost $tracking->response->data->price;
  962.                             }
  963.                             if ($cost == null) {
  964.                                 $cost 0;
  965.                             }
  966.                         } else {
  967.                             $cost 0;
  968.                         }
  969.                         $lead->setCost(floatval($cost));
  970.                     } else { // If HasOffers reject the lead as duplicate
  971.                         $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6);
  972.                         $lead->setStatus($lead_status); // duplicate lead
  973.                         //$resultin['duplicatetracking'] = true;
  974.                         $resultin['invalidtracking'] = true;
  975.                     }
  976.                 } elseif ($price !== && $lead->getHs() == 0){
  977.                     if ($project->getRevenueShare() == true) {
  978.                         if ($project->getId() == 80) {
  979.                             if ($project->getCommissions() == "0" || $project->getCommissions() == null) {
  980.                                 $commission 1;
  981.                             } else {
  982.                                 $commission $project->getCommissions();
  983.                             }
  984.                             $hasofferprice $price $commission 100;
  985.                             $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"];
  986.                             $ch curl_init();
  987.                             curl_setopt($chCURLOPT_URL$url);
  988.                             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  989.                             $response curl_exec($ch);
  990.                             curl_close($ch);
  991.                         } else {
  992.                             $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(1);
  993.                             $lead->setStatus($lead_status); // active lead
  994.                         }
  995.                     }
  996.                 } elseif ($project->getTracking() == null || ($project->getTracking() != null && $project->getTracking()->getId() == 2)) { // no tracking or tracking API Aff
  997.                     try {
  998.                         $url 'https://loudingads.api.hasoffers.com/Apiv3/json?NetworkToken=NETfLjuz52LTPJ2aOWXOruj7Lo7u7l&Target=Offer&Method=getAffiliatePayment&offer_id='.$data["offer"].'&affiliate_id='.$data["source"];
  999.                         $ch curl_init();
  1000.                         curl_setopt($chCURLOPT_URL$url);
  1001.                         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1002.                         $response curl_exec($ch);
  1003.                         $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;
  1004.                         $ch curl_init();
  1005.                         curl_setopt($chCURLOPT_URL$url);
  1006.                         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1007.                         curl_exec($ch);
  1008.                         curl_close($ch);
  1009.                     } catch (\Exception $e){
  1010.                     }
  1011.                 } else {
  1012.                     $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(1);
  1013.                     $lead->setStatus($lead_status); // active lead
  1014.                 }
  1015.             }
  1016.             // Test mode
  1017.             if ($this->testlead == true || str_contains($data['email'], '@test.com') == true || $this->testwebservice == true){
  1018.                 if ($this->testlead == true){ // Test email don't send to the customer but notify to the tracking systems
  1019.                     if ($project->getProjectEverflow() !== null){
  1020.                         //if project has everflow connection(API projects mainly) we set up source and offer
  1021.                         $data["source"] = (string)$project->getProjectEverflow()->getSource();
  1022.                         $data["offer"] = (string)$project->getProjectEverflow()->getOffer();
  1023.                     }
  1024.                     if ($lead->getProject()->getRevenueShare() == true){ // Project on Revenue share
  1025.                         if (isset($data["clickid"])){
  1026.                             $tracking $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
  1027.                         }elseif(isset($data["source"]) && isset($data["offer"])){
  1028.                             $tracking $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
  1029.                         }else{
  1030.                             $tracking false;
  1031.                         }
  1032.                     } else { // Project on fixed CPL
  1033.                         if (isset($data["clickid"])){
  1034.                             $tracking $this->forward('App\Controller\EverFlowController::createlead', array("cid" => $data["clickid"],"offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
  1035.                         }elseif(isset($data["source"]) && isset($data["offer"])){
  1036.                             $tracking $this->forward('App\Controller\EverFlowController::createlead', array("offer" => $data["offer"], "affid" => $data["source"],"lead"=>$lead->getId()))->getContent();
  1037.                         }else{
  1038.                             $tracking false;
  1039.                         }
  1040.                     }
  1041.                     if ($tracking == "true"){ // The tracking system has accepted the conversion
  1042.                         // Calculate the cost
  1043.                         try {
  1044.                             if ($project->getRevenueShare() == true){ // Project on Revenue share
  1045.                                 if ($project->getCommissions() == 0){
  1046.                                     $commission 1;
  1047.                                 }else{
  1048.                                     $commission $project->getCommissions();
  1049.                                 }
  1050.                                 $cost 0;
  1051.                             } else {  // Project fixed CPL: cost taken from the tracking system publisher's set up
  1052.                                 $cost $this->forward('App\Controller\EverFlowController::retrieveCost', array("offer" => $data["offer"], "affid" => $data["source"]))->getContent();
  1053.                                 if (json_decode($cost)->cost == && $project->getProjectEverflow() == null){
  1054.                                     $cost $this->forward('App\Controller\EverFlowController::retrieveCostOffer', array("offer" => $data["offer"]))->getContent();
  1055.                                 }else{
  1056.                                     $cost = array(
  1057.                                         "cost" => 0
  1058.                                     );
  1059.                                     $cost=json_encode($cost);
  1060.                                 }
  1061.                                 $cost json_decode($cost)->cost;
  1062.                             }
  1063.                         }catch (\Exception $e){
  1064.                             $cost 0;
  1065.                         }
  1066.                         $lead->setCost(floatval($cost));
  1067.                     }else{
  1068.                         $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6);
  1069.                         $lead->setStatus($lead_status); // duplicate lead
  1070.                         $resultin['invalidtracking'] = true;
  1071.                     }
  1072.                 }
  1073.                 $resultin["invalidtracking"] = false;
  1074.                 if ($lead->getStatus()->getId()==|| $lead->getStatus()->getId()==2){
  1075.                     if ($this->testlead == true ){
  1076.                         $resultout['validcampaign'] = true;
  1077.                         $resultout['validcustomer'] = true;
  1078.                     }
  1079.                     $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(18);
  1080.                     $lead->setStatus($lead_status); // active lead
  1081.                 }
  1082.             }
  1083.             $em->persist($lead);
  1084.             $em->flush();
  1085.         }
  1086.         /*if (($lead->getStatus()->getId()==1 ) || ( $lead->getStatus()->getId()==2) ||  ( $lead->getStatus()->getId()==18)){
  1087.             $this->sendToServer($lead);
  1088.         }*/
  1089.         /*if (isset($price)){
  1090.             $result = $this->closeprcs($project, $resultin, $resultout, $lead, $revenue, $sold);
  1091.             if (isset($apileadlog)){
  1092.                 $apileadlog->setLead($lead);
  1093.                 $apileadlog->setResponse($result->getContent());
  1094.                 $em->persist($lead);
  1095.                 $em->flush();
  1096.             }
  1097.             return $result ;
  1098.         }*/
  1099.         $this->listleadchecks($lead);
  1100.         $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  1101.         // Update Apileadlogs
  1102.         $this->inboundcalllog(nullnull$inboundcalllogjson_encode($result), $lead);
  1103.         return $this->json($result); // End of process
  1104.         //return $result;
  1105.     }
  1106.     public function closeprcs($project$resultin$resultout$lead$revenue$sold$price 0)
  1107.     {
  1108.         $em $this->getDoctrine()->getManager();
  1109.         // Update project numbers
  1110.         $project $this->updateproject($project$resultin$revenue,$sold,$lead);
  1111.         $em->persist($project);
  1112.         $em->flush();
  1113.         // Update project status with Capping
  1114.         /*if($project->getDailyreach() == $project->getDailycapping()) {
  1115.             $status = $this->getDoctrine()->getRepository(Status::class)->findOneById(10); // Daily capping reach
  1116.             $project->setStatus();
  1117.         }
  1118.         if($project->getMonthlyreach() == $project->getMonthlycapping()) {
  1119.             $status = $this->getDoctrine()->getRepository(Status::class)->findOneById(11); // Monthly capping reach
  1120.             $project->setStatus();
  1121.         }
  1122.         if($project->getValid() == $project->getCapping()) {
  1123.             $status = $this->getDoctrine()->getRepository(Status::class)->findOneById(5); // Capping reached set to paused
  1124.             $project->setStatus();
  1125.         }
  1126.         $em->persist($project);
  1127.         $em->flush();*/
  1128.         $result $this->feedback($resultin$resultout$lead$price);
  1129.         /* if (str_contains($lead->getEmail(), '@test.com') == true){
  1130.              dd("hola",$resultout,$resultin,$result);
  1131.          }*/
  1132.         return $result;
  1133.         return $this->json($result);
  1134.     }
  1135.     public function export($lead$project$campaigns) {
  1136.         $em $this->getDoctrine()->getManager();
  1137.         $status $this->getDoctrine()->getRepository(Status::class)->findOneById(1); // active
  1138.         // Array for the final response
  1139.         $result = array(
  1140.             'validcampaign' => false,
  1141.             'validcustomer' => false,
  1142.             'revenue' => 0,
  1143.             'sold' => 0
  1144.         );
  1145.         // Check exclusivity from the project
  1146.         if($project->getExclusivity() == || $project->getExclusivity() == null) {
  1147.             $exclusivity count($campaigns);
  1148.         } else {
  1149.             $exclusivity $project->getExclusivity();
  1150.         }
  1151.         $c 1// Campaign counter
  1152.         foreach ($campaigns as $campaign) {
  1153.             $response 0// Default response for the campaign
  1154.             // Check if the lead has been already sent to the customer
  1155.             //if($testlead !== true && $testwebservice !== true) {
  1156.             //if($this->testlead !== true && $this->testwebservice !== true) { // don't check duplicate for test
  1157.             if($this->testwebservice !== true) { // check duplicate only for test
  1158.                 $repository $this->getDoctrine()->getRepository(Leadcampaign::class);
  1159.                 $query $repository->createQueryBuilder('lc');
  1160.                 $query->leftJoin('App:Campaign''c''WITH''lc.campaign = c.id');
  1161.                 $query->leftJoin('App:Lead''l''WITH''lc.lead = l.id');
  1162.                 $query->andWhere('c.id = :campaign');
  1163.                 $query->andWhere('(l.email = :email or l.phone = :phone)');
  1164.                 $query->setParameter('campaign',$campaign->getId());
  1165.                 $query->setParameter('email',$lead->getEmail());
  1166.                 $query->setParameter('phone',$lead->getPhone());
  1167.                 $query $query->getQuery();
  1168.                 $leadcampaign $query->getResult();
  1169.                 if(count($leadcampaign) > 0) { // email or phone already sent to the customer
  1170.                     continue;
  1171.                 }
  1172.             }
  1173.             // Get campaign's field
  1174.             $fieldscampaign $this->getDoctrine()->getRepository(Fieldcampaign::class)->findBy(
  1175.                 array(
  1176.                     'status' => $status,
  1177.                     'campaign' => $campaign
  1178.                 )
  1179.             );
  1180.             $fields = array();
  1181.             foreach ($fieldscampaign as $fc) {
  1182.                 $repository $this->getDoctrine()->getRepository(Field::class);
  1183.                 $query $repository->createQueryBuilder('c');
  1184.                 $query->addSelect('c');
  1185.                 $query->andWhere(':fieldcampaign MEMBER OF c.fieldcampaigns');
  1186.                 $query->setParameter('fieldcampaign'$fc->getId());
  1187.                 $query->andWhere('c.project = :project');
  1188.                 $query->setParameter('project'$project->getId());
  1189.                 $query $query->getQuery();
  1190.                 $field $query->getResult();
  1191.                 $fcvalue $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(
  1192.                     array(
  1193.                         'field' => $field,
  1194.                         'lead' => $lead
  1195.                     )
  1196.                 );
  1197.                 if ($fcvalue !== null) {
  1198.                     $fields[$fc->getName()] = $fcvalue->getValue();
  1199.                 } else {
  1200.                     $fields[$fc->getName()] = null;
  1201.                 }
  1202.             }
  1203.             $fields["original_lead_id"] = $lead->getId();
  1204.             // Validate campaign filter
  1205.             $filterresult $this->checkcampaignfilter($lead$campaign);
  1206.             if (str_contains($lead->getEmail(), '@loudingest.com') == true){
  1207.                 //dd($filterresult,$fields);
  1208.             }
  1209.             if ($filterresult == true) { // filter passed
  1210.                 $arraycheck[$campaign->getId()]['filter'] = 1;
  1211.                 if ((str_contains($lead->getEmail(), '@loudingest.com') == true && $campaign->getStatus()->getId() == 9) || (str_contains($lead->getEmail(), '@loudingest.com') == false && $campaign->getStatus()->getId() != 9)) {
  1212.                     if ($campaign->getValidation() == 1) { // If campaign has webservice validation, send lead via ws; fields are campaignfields
  1213.                         switch ($campaign->getId()) {
  1214.                             case 1// Loudingads leadgen ES
  1215.                                 $webservice $this->forward('App\Controller\WebserviceController::loudingads', array('data' => $fields'campaign' => 1))->getContent();
  1216.                                 break;
  1217.                             case 430// Solar UK Monetise
  1218.                                 $webservice $this->forward('App\Controller\WebserviceController::monetise', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1219.                                 break;
  1220.                             case 429// Kataisa Energia ES
  1221.                                 $webservice $this->forward('App\Controller\WebserviceController::kataisa', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1222.                                 break;
  1223.                             case 428// Claims UK Qubiq
  1224.                                 $webservice $this->forward('App\Controller\WebserviceController::qubiq', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1225.                                 break;
  1226.                             case 427// Maverick SolMedia Limited Solar UK
  1227.                                 $webservice $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1228.                                 break;
  1229.                             case 426// HomeSecurity NL 360 unitedmedia
  1230.                                 $webservice $this->forward('App\Controller\WebserviceController::unitedmedia360', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1231.                                 break;
  1232.                             case 425// Maverick SolMedia Limited Solar UK
  1233.                                 $webservice $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1234.                                 break;
  1235.                             case 424// Iberdrola Energia ES
  1236.                                 $webservice $this->forward('App\Controller\WebserviceController::iberdrola', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1237.                                 break;
  1238.                             case 423// MediaAdgo Energia ES
  1239.                                 $webservice $this->forward('App\Controller\WebserviceController::mediaadgo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1240.                                 break;
  1241.                             case 420// Consumer Insite Debt US
  1242.                                 $webservice $this->forward('App\Controller\WebserviceController::consumerinsite', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1243.                                 break;
  1244.                             case 419// Tresa Energia Solar ES Exclusive
  1245.                                 $webservice $this->forward('App\Controller\WebserviceController::tresa', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1246.                                 break;
  1247.                             case 418// Maverick SolMedia Limited Solar UK
  1248.                                 $webservice $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1249.                                 break;
  1250.                             case 417// Maverick SolMedia Limited Solar UK
  1251.                                 $webservice $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1252.                                 break;
  1253.                             case 416// Maverick SolMedia Limited Solar UK
  1254.                                 $webservice $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1255.                                 break;
  1256.                             case 415// Tresa Energia Solar ES Exclusive
  1257.                                 $webservice $this->forward('App\Controller\WebserviceController::tresa', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1258.                                 break;
  1259.                             case 414// Maverick SolMedia Limited Solar UK
  1260.                                 $webservice $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1261.                                 break;
  1262.                             case 413// Zonnepannelen NL Hilead
  1263.                                 $webservice $this->forward('App\Controller\WebserviceController::hilead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1264.                                 break;
  1265.                             case 412// Debt US Adventum
  1266.                                 $webservice $this->forward('App\Controller\WebserviceController::adventumllcdirect', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1267.                                 dd($webservice);
  1268.                                 break;
  1269.                             case 411// Zonnepannelen NL Hilead
  1270.                                 $webservice $this->forward('App\Controller\WebserviceController::hilead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1271.                                 break;
  1272.                             case 410// Solar ES Daa Gmbh
  1273.                                 $webservice $this->forward('App\Controller\WebserviceController::daagmbh', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1274.                                 break;
  1275.                             case 408// Solar DE Dlulisa
  1276.                                 $webservice $this->forward('App\Controller\WebserviceController::dlulisa', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1277.                                 break;
  1278.                             case 407// Debt UK Monetise
  1279.                                 $webservice $this->forward('App\Controller\WebserviceController::monetise', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1280.                                 break;
  1281.                             case 406// Zonnepanelen NL Solvari
  1282.                                 $webservice $this->forward('App\Controller\WebserviceController::solvari', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1283.                                 break;
  1284.                             case 405// Paneles Solares ES ExpertaSolar
  1285.                                 $webservice $this->forward('App\Controller\WebserviceController::expertasolar', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1286.                                 break;
  1287.                             case 404// Paneles Solares ES Habitissimo
  1288.                                 $webservice $this->forward('App\Controller\WebserviceController::habitissimo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1289.                                 break;
  1290.                             case 403// Solar NL VipLeads
  1291.                                 $webservice $this->forward('App\Controller\WebserviceController::vipsleads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1292.                                 break;
  1293.                             case 402// Solar ES Voltalia
  1294.                                 $webservice $this->forward('App\Controller\WebserviceController::voltalia', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1295.                                 break;
  1296.                             case 401// BEFR Panneaux Solaire Otoads
  1297.                                 $webservice $this->forward('App\Controller\WebserviceController::otoads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1298.                                 break;
  1299.                             case 399// Energia GanaEnergia
  1300.                                 $webservice $this->forward('App\Controller\WebserviceController::ganaenergia', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1301.                                 break;
  1302.                             case 398// Energia Repsol T2O
  1303.                                 $webservice $this->forward('App\Controller\WebserviceController::repsolt2o', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1304.                                 break;
  1305.                             case 397// Solar BENL OTOADS
  1306.                                 $webservice $this->forward('App\Controller\WebserviceController::otoads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1307.                                 break;
  1308.                             case 395// Solar BENL OTOADS
  1309.                                 $webservice $this->forward('App\Controller\WebserviceController::otoads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1310.                                 break;
  1311.                             case 394// Solar UK Spotdif
  1312.                                 $webservice $this->forward('App\Controller\WebserviceController::spotdif', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1313.                                 break;
  1314.                             case 393// Deuda ES Enley
  1315.                                 $webservice $this->forward('App\Controller\WebserviceController::enley', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1316.                                 break;
  1317.                             case 392// DeudaFix ES DeudaFix
  1318.                                 $webservice $this->forward('App\Controller\WebserviceController::deudafix', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1319.                                 break;
  1320.                             case 391// ZonnePannelen NL Innodora
  1321.                                 $webservice $this->forward('App\Controller\WebserviceController::innodora', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1322.                                 break;
  1323.                             case 390// Paneles Solares HolaLuz
  1324.                                 $webservice $this->forward('App\Controller\WebserviceController::holaluz', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1325.                                 break;
  1326.                             case 389// Paneles Solares ES
  1327.                                 $webservice $this->forward('App\Controller\WebserviceController::habitissimo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1328.                                 break;
  1329.                             case 387// Maverick SolMedia Limited Solar UK
  1330.                                 $webservice $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1331.                                 break;
  1332.                             case 386// Test Sellyourhouse
  1333.                                 $webservice $this->forward('App\Controller\WebserviceController::smhf', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1334.                                 break;
  1335.                             case 385// Eltex Solar ES
  1336.                                 $webservice $this->forward('App\Controller\WebserviceController::eltexsolar', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1337.                                 break;
  1338.                             case 384// Movagency Decesos
  1339.                                 $webservice $this->forward('App\Controller\WebserviceController::movadgency', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1340.                                 break;
  1341.                             case 383// Dlulisa Zonnepanelen NL
  1342.                                 $webservice $this->forward('App\Controller\WebserviceController::dlulisa', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1343.                                 break;
  1344.                             case 382// Dlulisa Zonnepanelen NL
  1345.                                 $webservice $this->forward('App\Controller\WebserviceController::dlulisa', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1346.                                 break;
  1347.                             case 381// Maverick SolMedia Limited Solar UK
  1348.                                 $webservice $this->forward('App\Controller\WebserviceController::maverickmedialimited', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1349.                                 break;
  1350.                             case 380// Paneles Solares ES ExpertaSolar
  1351.                                 $webservice $this->forward('App\Controller\WebserviceController::expertasolar', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1352.                                 break;
  1353.                             case 378// Test Sellyourhouse
  1354.                                 $webservice $this->forward('App\Controller\WebserviceController::smhf', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1355.                                 break;
  1356.                             case 377// Panneaux Solaire Gasmobi
  1357.                                 $webservice $this->forward('App\Controller\WebserviceController::gasmobi', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1358.                                 break;
  1359.                             case 376// Turbo Debt DebtUS
  1360.                                 $webservice $this->forward('App\Controller\WebserviceController::turbodebt', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1361.                                 break;
  1362.                             case 375// SolarCorp Panneaux Solaire
  1363.                                 $webservice $this->forward('App\Controller\WebserviceController::solarcorp', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1364.                                 break;
  1365.                             case 374// EngelEnergy Paneles Solares ES
  1366.                                 $webservice $this->forward('App\Controller\WebserviceController::engelenergy', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1367.                                 break;
  1368.                             case 373// House Selling US Sell My House Fast LLC
  1369.                                 $webservice $this->forward('App\Controller\WebserviceController::smhf', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1370.                                 break;
  1371.                             case 372// Rachat de Credit Devissima
  1372.                                 $webservice $this->forward('App\Controller\WebserviceController::devissima', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1373.                                 break;
  1374.                             case 370// Odd Marketing Roofing US
  1375.                                 $webservice $this->forward('App\Controller\WebserviceController::oddmarketing', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1376.                                 break;
  1377.                             case 369// Odd Marketing Roofing US
  1378.                                 $webservice $this->forward('App\Controller\WebserviceController::oddmarketing', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1379.                                 break;
  1380.                             case 368// Odd Marketing Roofing US
  1381.                                 $webservice $this->forward('App\Controller\WebserviceController::oddmarketing', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1382.                                 break;
  1383.                             case 367// Odd Marketing Windows US
  1384.                                 $webservice $this->forward('App\Controller\WebserviceController::oddmarketing', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1385.                                 break;
  1386.                             case 366// MediaBrava Seguros ES
  1387.                                 $webservice $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1388.                                 break;
  1389.                              case 364// Dlulisa Zonnepanelen NL
  1390.                                 $webservice $this->forward('App\Controller\WebserviceController::dlulisa', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1391.                                 break;
  1392.                             case 363// MediaBrava Seguros ES
  1393.                                 $webservice $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1394.                                 break;
  1395.                             case 362// MediaBrava Seguros ES
  1396.                                 $webservice $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1397.                                 break;
  1398.                             case 361// MediaBrava Seguros ES
  1399.                                 $webservice $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1400.                                 break;
  1401.                             case 360// MediaBrava Seguros ES
  1402.                                 $webservice $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1403.                                 break;
  1404.                             case 359// MediaBrava Seguros ES
  1405.                                 $webservice $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1406.                                 break;
  1407.                             case 358// MediaBrava Seguros ES
  1408.                                 $webservice $this->forward('App\Controller\WebserviceController::mediabrava', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1409.                                 break;
  1410.                             case 356// Billy Roof Internal
  1411.                                 $webservice $this->forward('App\Controller\WebserviceController::billyexternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1412.                                 break;
  1413.                             case 355// Billy Roof Internal
  1414.                                 $webservice $this->forward('App\Controller\WebserviceController::billy', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1415.                                 break;
  1416.                             case 354//Bathroom US AdventumLLC
  1417.                                 $webservice $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1418.                                 break;
  1419.                             case 353//Alarms US AdventumLLC
  1420.                                 $webservice $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1421.                                 break;
  1422.                             case 352//Flooring US AdventumLLC
  1423.                                 $webservice $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1424.                                 break;
  1425.                             case 351//Windows US AdventumLLC
  1426.                                 $webservice $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1427.                                 break;
  1428.                             case 350//Solar US AdventumLLC
  1429.                                 $webservice $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1430.                                 break;
  1431.                             case 349//Roof US AdventumLLC
  1432.                                 $webservice $this->forward('App\Controller\WebserviceController::adventumllc', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1433.                                 break;
  1434.                             case 346//Offerte B.V     Isolatie
  1435.                                 $webservice $this->forward('App\Controller\WebserviceController::offertebvnew', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1436.                                 break;
  1437.                             case 345//InterDM B.V     Hypotheek
  1438.                                 $webservice $this->forward('App\Controller\WebserviceController::interdmbv', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1439.                                 break;
  1440.                             case 344//ExchangeFlo Roofing US
  1441.                                 $webservice $this->forward('App\Controller\WebserviceController::exchangeflo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1442.                                 break;
  1443.                             case 343//ExchangeFlo Solar US
  1444.                                 $webservice $this->forward('App\Controller\WebserviceController::exchangeflo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1445.                                 break;
  1446.                             case 342//MYS Zonnepanelen NL
  1447.                                 $webservice $this->forward('App\Controller\WebserviceController::mys', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1448.                                 break;
  1449.                             case 340//SWN9 Zonnepanelen BENL
  1450.                                 $webservice $this->forward('App\Controller\WebserviceController::swingingmonkey', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1451.                                 dd($webservice);
  1452.                                 break;
  1453.                             case 338//grocasa
  1454.                                 $webservice $this->forward('App\Controller\WebserviceController::grocasa', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1455.                                 break;
  1456.                             case 337//Swinging Monkey Zonnepanelen
  1457.                                 $webservice $this->forward('App\Controller\WebserviceController::swingingmonkey', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1458.                                 break;
  1459.                             case 336//EDM Windows
  1460.                                 $webservice $this->forward('App\Controller\WebserviceController::EDM', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1461.                                 dd($webservice);
  1462.                                 break;
  1463.                             case 335//EDM Solar
  1464.                                 $webservice $this->forward('App\Controller\WebserviceController::EDM', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1465.                                 break;
  1466.                             case 334//Zonnepanelen Spark Digital LTD
  1467.                                 $webservice $this->forward('App\Controller\WebserviceController::sparkdigital', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1468.                                 break;
  1469.                             case 333//EDM Roofing
  1470.                                 $webservice $this->forward('App\Controller\WebserviceController::EDM', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1471.                                 break;
  1472.                             case 330//Trafficon FR
  1473.                                 $webservice $this->forward('App\Controller\WebserviceController::trafficon', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1474.                                 break;
  1475.                             case 329//Trafficon ES
  1476.                                 $webservice $this->forward('App\Controller\WebserviceController::trafficon', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1477.                                 break;
  1478.                             case 328//Trafficon DE
  1479.                                 $webservice $this->forward('App\Controller\WebserviceController::trafficon', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1480.                                 break;
  1481.                             case 327//Trafficon IT
  1482.                                 $webservice $this->forward('App\Controller\WebserviceController::trafficon', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1483.                                 break;
  1484.                             case 326//UptownLeads Windows
  1485.                                 $webservice $this->forward('App\Controller\WebserviceController::uptownleads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1486.                                 break;
  1487.                             case 325//UptownLeads Flooring
  1488.                                 $webservice $this->forward('App\Controller\WebserviceController::uptownleads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1489.                                 break;
  1490.                             case 324//UptownLeads Bathroom
  1491.                                 $webservice $this->forward('App\Controller\WebserviceController::uptownleads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1492.                                 break;
  1493.                             case 323//UptownLeads Alarm
  1494.                                 $webservice $this->forward('App\Controller\WebserviceController::uptownleads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1495.                                 break;
  1496.                             case 322//UptownLeads Roof
  1497.                                 $webservice $this->forward('App\Controller\WebserviceController::uptownleads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1498.                                 break;
  1499.                             case 321//UptownLeads Solar
  1500.                                 $webservice $this->forward('App\Controller\WebserviceController::uptownleadssolar', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1501.                                 break;
  1502.                             case 320//Drobu Bathroom
  1503.                                 $webservice $this->forward('App\Controller\WebserviceController::drobu', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1504.                                 break;
  1505.                             case 319//Drobu Premium Bathroom
  1506.                                 $webservice $this->forward('App\Controller\WebserviceController::drobupremium', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1507.                                 break;
  1508.                             case 318//Drobu Flooring
  1509.                                 $webservice $this->forward('App\Controller\WebserviceController::drobu', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1510.                                 break;
  1511.                             case 317//Drobu Premium Flooring
  1512.                                 $webservice $this->forward('App\Controller\WebserviceController::drobupremium', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1513.                                 break;
  1514.                             case 316//Drobu Windows
  1515.                                 $webservice $this->forward('App\Controller\WebserviceController::drobu', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1516.                                 break;
  1517.                             case 314//Drobu Premium Windows
  1518.                                 $webservice $this->forward('App\Controller\WebserviceController::drobupremium', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1519.                                 break;
  1520.                             case 313//Drobu Roofing
  1521.                                 $webservice $this->forward('App\Controller\WebserviceController::drobu', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1522.                                 break;
  1523.                             case 312//Drobu Premium Roofing
  1524.                                 $webservice $this->forward('App\Controller\WebserviceController::drobupremium', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1525.                                 break;
  1526.                             case 311//Drobu Solar
  1527.                                 $webservice $this->forward('App\Controller\WebserviceController::drobusolar', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1528.                                 break;
  1529.                             case 310//Drobu Solar Premium
  1530.                                 $webservice $this->forward('App\Controller\WebserviceController::drobupremiumsolar', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1531.                                 break;
  1532.                             case 309//Alpine Floor
  1533.                                 $webservice $this->forward('App\Controller\WebserviceController::alpine', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1534.                                 break;
  1535.                             case 306// Windows Addaftech US
  1536.                                 $webservice $this->forward('App\Controller\WebserviceController::addaftech', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1537.                                 break;
  1538.                             case 305// Paneles Solares ES Daicos
  1539.                                 $webservice $this->forward('App\Controller\WebserviceController::daicos', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1540.                                 break;
  1541.                             case 304// ZonnePanelen
  1542.                                 $webservice $this->forward('App\Controller\WebserviceController::offertebvnew', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1543.                                 break;
  1544.                             case 303// Alarms
  1545.                                 $webservice $this->forward('App\Controller\WebserviceController::remodelwell', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1546.                                 break;
  1547.                             case 302// Paneles Solares España
  1548.                                 $webservice $this->forward('App\Controller\WebserviceController::mediaadgo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1549.                                 break;
  1550.                             case 298// NL Zonnepanelen
  1551.                                 $webservice $this->forward('App\Controller\WebserviceController::yello', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1552.                                 break;
  1553.                             case 297// TESTS
  1554.                                 $webservice $this->forward('App\Controller\WebServiceController::post_'.$campaign->getId(), array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1555.                                 break;
  1556.                             case 294// US Roofing Acquire Crowd
  1557.                                 $webservice $this->forward('App\Controller\WebserviceController::acquirecrowd', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1558.                                 break;
  1559.                             case 293// NL Zonnepanelen SunnyGreen
  1560.                                 $webservice $this->forward('App\Controller\WebserviceController::sunnygreen', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1561.                                 break;
  1562.                             case 292// NL Zonnepanelen ABC Solar
  1563.                                 $webservice $this->forward('App\Controller\WebserviceController::abcsolar', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1564.                                 break;
  1565.                             case 291// PANELES SOLARES SOLAR PROFIT ES
  1566.                                 $webservice $this->forward('App\Controller\WebserviceController::solarprofit', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1567.                                 break;
  1568.                             case 290// NL Zonnepanelen Easydura
  1569.                                 $webservice $this->forward('App\Controller\WebserviceController::easydura', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1570.                                 break;
  1571.                             case 289// Roofing US SBBNET
  1572.                                 $webservice $this->forward('App\Controller\WebserviceController::sbbnet', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1573.                                 break;
  1574.                             case 284// Paneles Solares ES Digien
  1575.                                 $webservice $this->forward('App\Controller\WebserviceController::digien', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1576.                                 break;
  1577.                             case 282// Mentormut Senior
  1578.                                 $webservice $this->forward('App\Controller\WebserviceController::clicklab', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1579.                                 break;
  1580.                             case 281// Paneles Solares ES
  1581.                                 $webservice $this->forward('App\Controller\WebserviceController::clicklab', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1582.                                 break;
  1583.                             case 280// Panneaux Solaire FR
  1584.                                 $webservice $this->forward('App\Controller\WebserviceController::clicklab', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1585.                                 break;
  1586.                             case 278// Zonnepannelen NL Hilead
  1587.                                 $webservice $this->forward('App\Controller\WebserviceController::encompass', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1588.                                 break;
  1589.                             case 271// Zonnepannelen NL Hilead
  1590.                                 $webservice $this->forward('App\Controller\WebserviceController::hilead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1591.                                 break;
  1592.                             case 270// Zonnepannelen BENL OfferteBV
  1593.                                 $webservice $this->forward('App\Controller\WebserviceController::offertebvnew', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1594.                                 break;
  1595.                             case 269// Roofing US LongHome
  1596.                                 $webservice $this->forward('App\Controller\WebserviceController::longhome', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1597.                                 break;
  1598.                             case 268// Windows US SBBNET
  1599.                                 $webservice $this->forward('App\Controller\WebserviceController::sbbnet', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1600.                                 break;
  1601.                             case 267// Octo Paneles Solares
  1602.                                 $webservice $this->forward('App\Controller\WebserviceController::octo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1603.                                 break;
  1604.                             case 263// Assurance Voiture MeilleaurTaux
  1605.                                 $webservice $this->forward('App\Controller\WebserviceController::meilleaurtaux', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1606.                                 break;
  1607.                             case 262// Alarm Vivint Email renter
  1608.                                 $webservice $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1609.                                 break;
  1610.                             case 261// Alarm Vivint Email owner
  1611.                                 $webservice $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1612.                                 break;
  1613.                             case 260// Alarm ADT Email renter
  1614.                                 $webservice $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1615.                                 break;
  1616.                             case 259// Alarm ADT Email owner
  1617.                                 $webservice $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1618.                                 break;
  1619.                             case 258// Lead Giant Windows Solar US
  1620.                                 $webservice $this->forward('App\Controller\WebserviceController::leadgiant', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1621.                                 break;
  1622.                             case 257// Lead Giant Roofing Solar US
  1623.                                 $webservice $this->forward('App\Controller\WebserviceController::leadgiant', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1624.                                 break;
  1625.                             case 256// Lead Giant Bathroom Solar US
  1626.                                 $webservice $this->forward('App\Controller\WebserviceController::leadgiant', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1627.                                 break;
  1628.                             case 255// Alarms Solar US Vivint Nonemail renter
  1629.                                 $webservice $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1630.                                 break;
  1631.                             case 254// Alarms Solar US Vivint Nonemail owner
  1632.                                 $webservice $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1633.                                 break;
  1634.                             case 253// Alarms Solar US ADT Nonemail renter
  1635.                                 $webservice $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1636.                                 break;
  1637.                             case 252// Alarms Solar US ADT Nonemail owner
  1638.                                 $webservice $this->forward('App\Controller\WebserviceController::directagents', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1639.                                 break;
  1640.                             case 251// Bathroom Solar US
  1641.                                 $webservice $this->forward('App\Controller\WebserviceController::bluefire', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1642.                                 break;
  1643.                             case 250// Roofing Solar US
  1644.                                 $webservice $this->forward('App\Controller\WebserviceController::bluefire', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1645.                                 break;
  1646.                             case 249// Windows Solar US
  1647.                                 $webservice $this->forward('App\Controller\WebserviceController::bluefire', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1648.                                 break;
  1649.                             case 248// Bathroom Home You US
  1650.                                 $webservice $this->forward('App\Controller\WebserviceController::homeyou', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1651.                                 break;
  1652.                             case 247// Flooring Home You US
  1653.                                 $webservice $this->forward('App\Controller\WebserviceController::homeyou', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1654.                                 break;
  1655.                             case 246// Roof Home You US
  1656.                                 $webservice $this->forward('App\Controller\WebserviceController::homeyou', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1657.                                 break;
  1658.                             case 245// Windows DMS US
  1659.                                 $webservice $this->forward('App\Controller\WebserviceController::DMS', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1660.                                 break;
  1661.                             case 244// LeadNovate Solar Panel
  1662.                                 $webservice $this->forward('App\Controller\WebserviceController::leadnovate', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1663.                                 break;
  1664.                             case 243// Flooring Ever Connect US
  1665.                                 $webservice $this->forward('App\Controller\WebserviceController::everconnect', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1666.                                 break;
  1667.                             case 242// Bathroom Ever Connect US
  1668.                                 $webservice $this->forward('App\Controller\WebserviceController::everconnect', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1669.                                 break;
  1670.                             case 241// Roof Ever Connect US
  1671.                                 $webservice $this->forward('App\Controller\WebserviceController::everconnect', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1672.                                 break;
  1673.                             case 240// Colossus Solar Panel
  1674.                                 $webservice $this->forward('App\Controller\WebserviceController::newcolossus', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1675.                                 break;
  1676.                             case 239// /TEST PANELES SOLARES
  1677.                                 $webservice $this->forward('App\Controller\WebserviceController::mediaadgo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1678.                                 break;
  1679.                             case 238// Windows Ever Connect US
  1680.                                 $webservice $this->forward('App\Controller\WebserviceController::everconnect', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1681.                                 break;
  1682.                             case 237// BlueFire Solar US
  1683.                                 $webservice $this->forward('App\Controller\WebserviceController::bluefire', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1684.                                 break;
  1685.                             case 236// Solar Momentum US
  1686.                                 $webservice $this->forward('App\Controller\WebserviceController::momentum', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1687.                                 break;
  1688.                             case 235// Bathroom Click Dealer US
  1689.                                 $webservice $this->forward('App\Controller\WebserviceController::clickdealer', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1690.                                 break;
  1691.                             case 234// Windows Click Dealer US
  1692.                                 $webservice $this->forward('App\Controller\WebserviceController::clickdealer', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1693.                                 break;
  1694.                             case 233// Roofing Click Dealer US
  1695.                                 $webservice $this->forward('App\Controller\WebserviceController::clickdealer', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1696.                                 break;
  1697.                             case 232// Roofing Click Dealer US
  1698.                                 $webservice $this->forward('App\Controller\WebserviceController::clickdealer', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1699.                                 break;
  1700.                             case 230// Solar Fluent US
  1701.                                 $webservice $this->forward('App\Controller\WebserviceController::fluentsolar', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1702.                                 break;
  1703.                             case 229//LinkEtLead PV12
  1704.                                 $webservice $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1705.                                 break;
  1706.                             case 228// Windows Home You US
  1707.                                 $webservice $this->forward('App\Controller\WebserviceController::homeyou', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1708.                                 break;
  1709.                             case 227// Windows Addaftech US
  1710.                                 $webservice $this->forward('App\Controller\WebserviceController::addaftech', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1711.                                 break;
  1712.                             case 226// Roofing Addaftech US
  1713.                                 $webservice $this->forward('App\Controller\WebserviceController::addaftech', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1714.                                 break;
  1715.                             case 225// Bathroom Addaftech US
  1716.                                 $webservice $this->forward('App\Controller\WebserviceController::addaftech', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1717.                                 break;
  1718.                             case 224// Solar Addaftech US
  1719.                                 $webservice $this->forward('App\Controller\WebserviceController::addaftech', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1720.                                 break;
  1721.                             case 223// Roof DMS US
  1722.                                 $webservice $this->forward('App\Controller\WebserviceController::DMS', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1723.                                 break;
  1724.                             case 222// Roof DMS US
  1725.                                 $webservice $this->forward('App\Controller\WebserviceController::DMS', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1726.                                 break;
  1727.                             case 221//LinkEtLead PV14
  1728.                                 $webservice $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1729.                                 break;
  1730.                             case 220// Blue ink Alarms
  1731.                                 $webservice $this->forward('App\Controller\WebserviceController::blueinkexternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1732.                                 break;
  1733.                             case 219// Blue ink Bathroom
  1734.                                 $webservice $this->forward('App\Controller\WebserviceController::blueinkexternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1735.                                 break;
  1736.                             case 218// Blue ink Flooring
  1737.                                 $webservice $this->forward('App\Controller\WebserviceController::blueinkexternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1738.                                 break;
  1739.                             case 217// Blue ink Roofing
  1740.                                 $webservice $this->forward('App\Controller\WebserviceController::blueinkexternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1741.                                 break;
  1742.                             case 216// Blue ink Solar Panels
  1743.                                 $webservice $this->forward('App\Controller\WebserviceController::blueinkexternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1744.                                 break;
  1745.                             case 215// Bathroom Presidio Interactive Corp. US
  1746.                                 $webservice $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1747.                                 break;
  1748.                             case 214// Windows Presidio Interactive Corp. US
  1749.                                 $webservice $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1750.                                 break;
  1751.                             case 213// Flooring Presidio Interactive Corp. US
  1752.                                 $webservice $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1753.                                 break;
  1754.                             case 212// Roofing Presidio Interactive Corp. US
  1755.                                 $webservice $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1756.                                 break;
  1757.                             case 211//Windows US Encompass
  1758.                                 $webservice $this->forward('App\Controller\WebserviceController::encompass', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1759.                                 break;
  1760.                             case 210//Bathroom US Encompass
  1761.                                 $webservice $this->forward('App\Controller\WebserviceController::encompass', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1762.                                 break;
  1763.                             case 209//Roof US Encompass
  1764.                                 $webservice $this->forward('App\Controller\WebserviceController::encompass', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1765.                                 break;
  1766.                             case 208//Solar US Encompass
  1767.                                 $webservice $this->forward('App\Controller\WebserviceController::encompass', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1768.                                 break;
  1769.                             case 207// Kozijnen Offertevergelijker
  1770.                                 $webservice $this->forward('App\Controller\WebserviceController::offertevergelijker', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1771.                                 break;
  1772.                             case 206// TrapRenovatie Offertevergelijker
  1773.                                 $webservice $this->forward('App\Controller\WebserviceController::offertevergelijker', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1774.                                 break;
  1775.                             case 205// Solar DMS US
  1776.                                 $webservice $this->forward('App\Controller\WebserviceController::DMS', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1777.                                 break;
  1778.                             case 204// Alarms Presidio Interactive Corp. US
  1779.                                 $webservice $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1780.                                 break;
  1781.                             case 203// Solar Panel Presidio Interactive Corp. US
  1782.                                 $webservice $this->forward('App\Controller\WebserviceController::presidiointeractive', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1783.                                 break;
  1784.                             case 201// CostaBlanca Solar
  1785.                                 $webservice $this->forward('App\Controller\WebserviceController::costablanca', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1786.                                 break;
  1787.                             case 200// Miligroup Security
  1788.                                 $webservice $this->forward('App\Controller\WebserviceController::miligroup', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1789.                                 break;
  1790.                             case 199// Miligroup Bathroom
  1791.                                 $webservice $this->forward('App\Controller\WebserviceController::miligroup', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1792.                                 break;
  1793.                             case 198// Finetwork ES
  1794.                                 /* if(str_contains($lead->getEmail(), '@test.com') == true){
  1795.                                     $webservice = array(
  1796.                                         "response" => "test",
  1797.                                         "wscall" => "none",
  1798.                                         "check" => "1",
  1799.                                         "price" => "0",
  1800.                                     );
  1801.                                      $webservice = json_encode($webservice);
  1802.                                  }else{*/
  1803.                                 $webservice $this->forward('App\Controller\WebserviceController::finetwork', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1804.                                 /* }*/
  1805.                                 break;
  1806.                             case 197// Billy Windows External
  1807.                                 $webservice $this->forward('App\Controller\WebserviceController::billyexternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1808.                                 break;
  1809.                             case 196// Billy Windows Internal
  1810.                                 $webservice $this->forward('App\Controller\WebserviceController::billy', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1811.                                 break;
  1812.                             case 195// Billy Flooring External
  1813.                                 $webservice $this->forward('App\Controller\WebserviceController::billyexternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1814.                                 break;
  1815.                             case 194// Billy Flooring Internal
  1816.                                 $webservice $this->forward('App\Controller\WebserviceController::billy', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1817.                                 break;
  1818.                             case 193// Billy Alarm External
  1819.                                 $webservice $this->forward('App\Controller\WebserviceController::billyexternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1820.                                 break;
  1821.                             case 192// Billy Alarm Internal
  1822.                                 $webservice $this->forward('App\Controller\WebserviceController::billy', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1823.                                 break;
  1824.                             case 191// Billy Solar External
  1825.                                 $webservice $this->forward('App\Controller\WebserviceController::billyexternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1826.                                 break;
  1827.                             case 190// Billy Solar
  1828.                                 $webservice $this->forward('App\Controller\WebserviceController::billy', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1829.                                 break;
  1830.                             case 189// RemodelWell Bathroom
  1831.                                 $webservice $this->forward('App\Controller\WebserviceController::remodelwell', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1832.                                 break;
  1833.                             case 188// RemodelWell Windows
  1834.                                 $webservice $this->forward('App\Controller\WebserviceController::remodelwell', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1835.                                 break;
  1836.                             case 187// RemodelWell Roof
  1837.                                 $webservice $this->forward('App\Controller\WebserviceController::remodelwell', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1838.                                 break;
  1839.                             case 186// RemodelWell Solar
  1840.                                 $webservice $this->forward('App\Controller\WebserviceController::YAC', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1841.                                 break;
  1842.                             case 185// RemodelWell Solar
  1843.                                 $webservice $this->forward('App\Controller\WebserviceController::bobex', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1844.                                 break;
  1845.                             case 184// RemodelWell Solar
  1846.                                 $webservice $this->forward('App\Controller\WebserviceController::remodelwell', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1847.                                 break;
  1848.                             case 183// Miligroup Windows
  1849.                                 $webservice $this->forward('App\Controller\WebserviceController::miligroup', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1850.                                 break;
  1851.                             case 182// Miligroup Flooring
  1852.                                 $webservice $this->forward('App\Controller\WebserviceController::miligroup', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1853.                                 break;
  1854.                             case 181//LinkEtLead PAC14
  1855.                                 $webservice $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1856.                                 break;
  1857.                             case 180//Confluent Panneaux Solaire
  1858.                                 $webservice $this->forward('App\Controller\WebserviceController::confluent', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1859.                                 break;
  1860.                             case 179//Confluent Panneaux Solaire
  1861.                                 $webservice $this->forward('App\Controller\WebserviceController::confluent', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1862.                                 break;
  1863.                             case 178//Digital in perf Panneaux Solaire
  1864.                                 $webservice $this->forward('App\Controller\WebserviceController::dedeco', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1865.                                 break;
  1866.                             case 177//Digital in perf Panneaux Solaire
  1867.                                 $webservice $this->forward('App\Controller\WebserviceController::digitalinperf', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1868.                                 break;
  1869.                             case 176//Digital in perf Pac Chauffage
  1870.                                 $webservice $this->forward('App\Controller\WebserviceController::digitalinperf', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1871.                                 break;
  1872.                             case 174// Miligroup Roof
  1873.                                 $webservice $this->forward('App\Controller\WebserviceController::dedeco', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1874.                                 break;
  1875.                             case 173// Miligroup Roof
  1876.                                 $webservice $this->forward('App\Controller\WebserviceController::miligroup', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1877.                                 break;
  1878.                             case 172// Bobex Zonnepanelen BENL
  1879.                                 $webservice $this->forward('App\Controller\WebserviceController::bobex', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1880.                                 break;
  1881.                             case 171//Alarms Blue Ink
  1882.                                 $webservice $this->forward('App\Controller\WebserviceController::YAC', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1883.                                 break;
  1884.                             case 170//Alarms Blue Ink
  1885.                                 $webservice $this->forward('App\Controller\WebserviceController::blueinkinternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1886.                                 break;
  1887.                             case 169//Alarms Allied Digital Media
  1888.                                 $webservice $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1889.                                 break;
  1890.                             case 168//Vivint Alarms
  1891.                                 $webservice $this->forward('App\Controller\WebserviceController::vivint', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1892.                                 break;
  1893.                             case 167//Modernize Alarms
  1894.                                 $webservice $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1895.                                 break;
  1896.                             case 166:// Lets Make A Lead Alarms
  1897.                                 $webservice $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1898.                                 break;
  1899.                             case 165//LinkEtLead PV11 panneaux solaire
  1900.                                 $webservice $this->forward('App\Controller\WebserviceController::convergedirect', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1901.                                 break;
  1902.                             case 164//LinkEtLead PV11 panneaux solaire
  1903.                                 $webservice $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1904.                                 break;
  1905.                             case 163//Roofing Allied Digital Media
  1906.                                 $webservice $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1907.                                 break;
  1908.                             case 162//Bathroom Allied Digital Media
  1909.                                 $webservice $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1910.                                 break;
  1911.                             case 161//Flooring Allied Digital Media
  1912.                                 $webservice $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1913.                                 break;
  1914.                             case 160//Windows Allied Digital Media
  1915.                                 $webservice $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1916.                                 break;
  1917.                             case 159//Windows Allied Digital Media
  1918.                                 $webservice $this->forward('App\Controller\WebserviceController::allieddigitalmedia', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1919.                                 break;
  1920.                             case 158//Bathroom LeadVision
  1921.                                 $webservice $this->forward('App\Controller\WebserviceController::leadvision', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1922.                                 break;
  1923.                             case 157//Solar LeadVision
  1924.                                 $webservice $this->forward('App\Controller\WebserviceController::leadvision', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1925.                                 break;
  1926.                             case 156//LinkEtLead PV10 panneaux solaire
  1927.                                 $webservice $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1928.                                 break;
  1929.                             case 155//ADT Solar
  1930.                                 $webservice $this->forward('App\Controller\WebserviceController::ADT', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1931.                                 break;
  1932.                             case 154//Bluewings Bathroom
  1933.                                 $webservice $this->forward('App\Controller\WebserviceController::bluewings', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1934.                                 break;
  1935.                             case 153//Bluewings Bathroom
  1936.                                 $webservice $this->forward('App\Controller\WebserviceController::bluewings', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1937.                                 break;
  1938.                             case 152//Bluewings Roof
  1939.                                 $webservice $this->forward('App\Controller\WebserviceController::bluewings', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1940.                                 break;
  1941.                             case 151//Bluewings Windows
  1942.                                 $webservice $this->forward('App\Controller\WebserviceController::bluewings', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1943.                                 break;
  1944.                             case 150//Bluewings Solar
  1945.                                 $webservice $this->forward('App\Controller\WebserviceController::bluewings', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1946.                                 break;
  1947.                             case 149//LinkEtLead
  1948.                                 $webservice $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1949.                                 break;
  1950.                             case 148//Alpine Bathroom
  1951.                                 $webservice $this->forward('App\Controller\WebserviceController::alpine', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1952.                                 break;
  1953.                             case 147//Alpine Roofing
  1954.                                 $webservice $this->forward('App\Controller\WebserviceController::alpine', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1955.                                 break;
  1956.                             case 146//Alpine Windows
  1957.                                 $webservice $this->forward('App\Controller\WebserviceController::alpine', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1958.                                 break;
  1959.                             case 144//Pointer Flooring
  1960.                                 $webservice $this->forward('App\Controller\WebserviceController::alpine', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1961.                                 break;
  1962.                             case 143//Pointer Flooring
  1963.                                 $webservice $this->forward('App\Controller\WebserviceController::pointer', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1964.                                 break;
  1965.                             case 142//IntelHouseMarketing Flooring
  1966.                                 $webservice $this->forward('App\Controller\WebserviceController::intelhouse', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1967.                                 break;
  1968.                             case 141//IntelHouseMarketing Windows
  1969.                                 $webservice $this->forward('App\Controller\WebserviceController::intelhouse', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1970.                                 break;
  1971.                             case 140//IntelHouseMarketing Bath
  1972.                                 $webservice $this->forward('App\Controller\WebserviceController::intelhouse', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1973.                                 break;
  1974.                             case 139//IntelHouseMarketing Roof
  1975.                                 $webservice $this->forward('App\Controller\WebserviceController::intelhouse', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1976.                                 break;
  1977.                             case 138//IntelHouseMarketing Solar
  1978.                                 $webservice $this->forward('App\Controller\WebserviceController::intelhouse', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1979.                                 break;
  1980.                             case 137//Modernize Solar
  1981.                                 $webservice $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1982.                                 break;
  1983.                             case 136//Pointer Windows US
  1984.                                 $webservice $this->forward('App\Controller\WebserviceController::pointer', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1985.                                 break;
  1986.                             case 135//Invexperto
  1987.                                 $webservice $this->forward('App\Controller\WebserviceController::DBInvest', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1988.                                 break;
  1989.                             case 134//Pointer Roof US
  1990.                                 $webservice $this->forward('App\Controller\WebserviceController::pointer', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1991.                                 break;
  1992.                             case 133//Pointer Bathroom US
  1993.                                 $webservice $this->forward('App\Controller\WebserviceController::pointer', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1994.                                 break;
  1995.                             case 132//Pointer Solar US
  1996.                                 $webservice $this->forward('App\Controller\WebserviceController::pointer', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  1997.                                 break;
  1998.                             case 131//Turtle Bath US
  1999.                                 $webservice $this->forward('App\Controller\WebserviceController::offertebv', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2000.                                 break;
  2001.                             case 123//Turtle Bath US
  2002.                                 $webservice $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2003.                                 break;
  2004.                             case 122//Turtle Bath US
  2005.                                 $webservice $this->forward('App\Controller\WebserviceController::turtleleads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2006.                                 break;
  2007.                             case 121//Turtle Windows US
  2008.                                 $webservice $this->forward('App\Controller\WebserviceController::turtleleads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2009.                                 break;
  2010.                             case 120//Turtle Floor US
  2011.                                 $webservice $this->forward('App\Controller\WebserviceController::turtleleads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2012.                                 break;
  2013.                             case 119//Turtle Roof US
  2014.                                 $webservice $this->forward('App\Controller\WebserviceController::turtleleads', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2015.                                 break;
  2016.                             case 118//Turtle Solar US
  2017.                                 $webservice $this->forward('App\Controller\WebserviceController::turtleleadssolar', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2018.                                 break;
  2019.                             case 117//Cactus
  2020.                                 $webservice $this->forward('App\Controller\WebserviceController::cactus', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2021.                                 break;
  2022.                             case 116:// Blue ink Bathroom
  2023.                                 $webservice $this->forward('App\Controller\WebserviceController::blueinkinternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2024.                                 break;
  2025.                             case 115:// Modernize Bathroom
  2026.                                 $webservice $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2027.                                 break;
  2028.                             case 114:// Lets Make A Lead Bathroom
  2029.                                 $webservice $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2030.                                 break;
  2031.                             case 113:// Top10 Ping/Post Roofing
  2032.                                 $webservice $this->forward('App\Controller\WebserviceController::top10ping', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2033.                                 break;
  2034.                             case 112:// LINKETLEAD PAC
  2035.                                 $webservice $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2036.                                 break;
  2037.                             case 111:// RGR MARKETING ROOFING
  2038.                                 $webservice $this->forward('App\Controller\WebserviceController::RGR', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2039.                                 break;
  2040.                             case 109:// RGR MARKETING ROOFING
  2041.                                 $webservice $this->forward('App\Controller\WebserviceController::RGR', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2042.                                 break;
  2043.                             case 110:// RGR MARKETING ROOFING
  2044.                                 $webservice $this->forward('App\Controller\WebserviceController::RGR', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2045.                                 break;
  2046.                             case 106:
  2047.                             case 103:
  2048.                             case 102:
  2049.                             case 108//
  2050.                                 $webservice $this->forward('App\Controller\WebserviceController::YAC', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2051.                                 break;
  2052.                             case 107//
  2053.                                 $webservice $this->forward('App\Controller\WebserviceController::cactus', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2054.                                 break;
  2055.                             case 99:
  2056.                             case 105// Airo Windows US
  2057.                                 $webservice $this->forward('App\Controller\WebserviceController::airo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2058.                                 break;
  2059.                             case 101// Top10 Windows US
  2060.                                 $webservice $this->forward('App\Controller\WebserviceController::TOP10', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2061.                                 break;
  2062.                             case 100// Modernize Windows US
  2063.                                 $webservice $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2064.                                 break;
  2065.                             case 98// Letsmakealead Windows US
  2066.                                 $webservice $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2067.                                 break;
  2068.                             case 97// Blue ink Floor US
  2069.                                 $webservice $this->forward('App\Controller\WebserviceController::airo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2070.                                 break;
  2071.                             case 96// Blue ink Floor US
  2072.                                 $webservice $this->forward('App\Controller\WebserviceController::blueinkinternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2073.                                 break;
  2074.                             case 95// Modernize Flooring US
  2075.                                 $webservice $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2076.                                 break;
  2077.                             case 94// Airo Roof US
  2078.                                 $webservice $this->forward('App\Controller\WebserviceController::airo', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2079.                                 break;
  2080.                             case 93// Letsmakealead Roof US
  2081.                                 $webservice $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2082.                                 break;
  2083.                             case 91// Letsmakealead Floor US
  2084.                                 $webservice $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2085.                                 break;
  2086.                             case 90// EMPIRE FLOORING FLOOR US
  2087.                                 $webservice $this->forward('App\Controller\WebserviceController::empireflooring', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2088.                                 break;
  2089.                             case 89// BLUE INK ROOFING US
  2090.                                 $webservice $this->forward('App\Controller\WebserviceController::blueinkinternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2091.                                 break;
  2092.                             case 88// Modernize Roofing US
  2093.                                 $webservice $this->forward('App\Controller\WebserviceController::modernize', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2094.                                 break;
  2095.                             case 87// TOP 10 Roof US
  2096.                                 $webservice $this->forward('App\Controller\WebserviceController::TOP10', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2097.                                 break;
  2098.                             case 85// novaxpress SOLAR PANEL
  2099.                                 $webservice $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2100.                                 break;
  2101.                             case 84// LETSMAKELEAD SOLAR PANEL
  2102.                                 $webservice $this->forward('App\Controller\WebserviceController::LMAD', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2103.                                 break;
  2104.                             case 83// TOP10 MARKETING SOLAR PANEL
  2105.                                 $webservice $this->forward('App\Controller\WebserviceController::TOP10', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2106.                                 break;
  2107.                             case 82// RGR MARKETING SOLAR PANEL
  2108.                                 $webservice $this->forward('App\Controller\WebserviceController::RGR', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2109.                                 break;
  2110.                             case 78:
  2111.                             case 79:
  2112.                             case 80:
  2113.                             case 81// BlueMedia CRYPTO BE
  2114.                                 $webservice $this->forward('App\Controller\WebserviceController::bluemedia', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2115.                                 break;
  2116.                             case 77// SAMARA ENERGIA SL PANELES SOLARES
  2117.                                 $webservice $this->forward('App\Controller\WebserviceController::samara', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2118.                                 break;
  2119.                             case 76// Sunrun Solas Paneles
  2120.                                 $webservice $this->forward('App\Controller\WebserviceController::sunrun', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2121.                                 break;
  2122.                             case 75// Colossus Solas Paneles
  2123.                                 $webservice $this->forward('App\Controller\WebserviceController::colossus', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2124.                                 break;
  2125.                             case 74// Blue ink Solas Paneles
  2126.                                 $webservice $this->forward('App\Controller\WebserviceController::blueinkinternal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2127.                                 break;
  2128.                             case 73// SBBNET Solas Paneles
  2129.                                 $webservice $this->forward('App\Controller\WebserviceController::SBBNET', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2130.                                 break;
  2131.                             case 72// SDM Solas Paneles
  2132.                                 $webservice $this->forward('App\Controller\WebserviceController::SDM', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2133.                                 break;
  2134.                             case 71// Pac Chauffage LinketLead
  2135.                                 $webservice $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2136.                                 break;
  2137.                             case 70// Mobipium Solar Paneles
  2138.                                 $webservice $this->forward('App\Controller\WebserviceController::mobipium', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2139.                                 break;
  2140.                             case 68// PARKING Bewowin
  2141.                                 $webservice $this->forward('App\Controller\WebserviceController::betowin', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2142.                                 break;
  2143.                             case 67// CPF Betowin
  2144.                                 $webservice $this->forward('App\Controller\WebserviceController::betowin', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2145.                                 break;
  2146.                             case 66// Panneaux LinkEtLead
  2147.                                 $webservice $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2148.                                 break;
  2149.                             case 65// Panneaux LinkEtLead
  2150.                                 $webservice $this->forward('App\Controller\WebserviceController::linketlead', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2151.                                 break;
  2152.                             case 64// Internovous Forex NL
  2153.                                 $webservice $this->forward('App\Controller\WebserviceController::internovus', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2154.                                 break;
  2155.                             case 63// SOI HolaLuz
  2156.                                 $webservice $this->forward('App\Controller\WebserviceController::horaluz', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2157.                                 break;
  2158.                             case 62// WEENDEAL, Mutuelle Seniors
  2159.                                 $webservice $this->forward('App\Controller\WebserviceController::weendal', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2160.                                 break;
  2161.                             case 61// CLIDOM-SOLAR, S.L. Paneles Solares Spain
  2162.                                 $webservice $this->forward('App\Controller\WebserviceController::horaluz', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2163.                                 break;
  2164.                             case 60// Novaexpress Mutuelle Seniors
  2165.                                 $webservice $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2166.                                 break;
  2167.                             case 59// PAC Chauffage
  2168.                                 $webservice $this->forward('App\Controller\WebserviceController::spin8', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2169.                                 break;
  2170.                             case 58// Courtalys
  2171.                                 $webservice $this->forward('App\Controller\WebserviceController::blackandwhite', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2172.                                 break;
  2173.                             case 57// Courtalys
  2174.                                 $webservice $this->forward('App\Controller\WebserviceController::courtalys', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2175.                                 break;
  2176.                             case 55// black and white investissment
  2177.                                 $webservice $this->forward('App\Controller\WebserviceController::blackandwhite', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2178.                                 break;
  2179.                             case 54// black and white crypto fr
  2180.                                 $webservice $this->forward('App\Controller\WebserviceController::blackandwhite', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2181.                                 break;
  2182.                             case 52// Novaexpress PAC chauffage
  2183.                                 $webservice $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2184.                                 break;
  2185.                             case 51// CBM Adoucisseur d'eau
  2186.                                 $webservice $this->forward('App\Controller\WebserviceController::cbm', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2187.                                 break;
  2188.                             case 50// Forex FR Mythos
  2189.                                 $webservice $this->forward('App\Controller\WebserviceController::mythos', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2190.                                 break;
  2191.                             case 49// Novaexpress Adoucisseur d'eau
  2192.                                 $webservice $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2193.                                 break;
  2194.                             case 48// Forex NL Mythos
  2195.                                 $webservice $this->forward('App\Controller\WebserviceController::mythos', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2196.                                 break;
  2197.                             case 47// Forex IT Mythos
  2198.                                 $webservice $this->forward('App\Controller\WebserviceController::mythos', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2199.                                 break;
  2200.                             case 45// Forex IT Internovus
  2201.                                 $webservice $this->forward('App\Controller\WebserviceController::internovus', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2202.                                 break;
  2203.                             case 44// Amazon Invest BENL
  2204.                                 $webservice $this->forward('App\Controller\WebserviceController::maisontraffic', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2205.                                 break;
  2206.                             case 43// Amazon Invest NL
  2207.                                 $webservice $this->forward('App\Controller\WebserviceController::maisontraffic', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2208.                                 break;
  2209.                             case 42// Amazon Invest IT
  2210.                                 $webservice $this->forward('App\Controller\WebserviceController::maisontraffic', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2211.                                 break;
  2212.                             case 40// Bobex Zonnepanelen BENL
  2213.                                 $webservice $this->forward('App\Controller\WebserviceController::bobex', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2214.                                 break;
  2215.                             case 36// Atlas Power
  2216.                                 $webservice $this->forward('App\Controller\WebserviceController::atlaspower', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2217.                                 break;
  2218.                             case 35// Solar Concept
  2219.                                 $webservice $this->forward('App\Controller\WebserviceController::solarconcept', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2220.                                 break;
  2221.                             case 34// BewustCollectief
  2222.                                 $webservice $this->forward('App\Controller\WebserviceController::bewustcollectief', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2223.                                 break;
  2224.                             case 30:// Panneaux Solaire
  2225.                                 $webservice $this->forward('App\Controller\WebserviceController::spin8', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2226.                                 break;
  2227.                             case 27// CPF Spin8
  2228.                                 $webservice $this->forward('App\Controller\WebserviceController::spin8', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2229.                                 break;
  2230.                             case 23// Bobex Isolatie
  2231.                                 $webservice $this->forward('App\Controller\WebserviceController::bobex', array('data' => $fields'campaign' => 23))->getContent();
  2232.                                 break;
  2233.                             case 21// Bobex Zonnepanelen NL
  2234.                                 $webservice $this->forward('App\Controller\WebserviceController::bobex', array('data' => $fields'campaign' => 21))->getContent();
  2235.                                 break;
  2236.                             case 20// Get up media panneaux solaires
  2237.                                 $webservice $this->forward('App\Controller\WebserviceController::getupmedia', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2238.                                 break;
  2239.                             case 19// Novaexpress panneaux solaires
  2240.                                 $webservice $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields'campaign' => 19))->getContent();
  2241.                                 break;
  2242.                             case 17// Novaexpress Livret
  2243.                                 $webservice $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields'campaign' => 17))->getContent();
  2244.                                 break;
  2245.                             case 26// Novaexpress CPF
  2246.                                 $webservice $this->forward('App\Controller\WebserviceController::novaxpress', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2247.                                 break;
  2248.                             case 14// Offerte BV Isolatie
  2249.                                 $webservice $this->forward('App\Controller\WebserviceController::offertebv', array('data' => $fields'campaign' => 14))->getContent();
  2250.                                 break;
  2251.                             case 13// Offerte BV Zonnepanelen
  2252.                                 $webservice $this->forward('App\Controller\WebserviceController::offertebv', array('data' => $fields'campaign' => 13))->getContent();
  2253.                                 break;
  2254.                             case 11// Offertevergelijker Zonnepanelen
  2255.                                 $webservice $this->forward('App\Controller\WebserviceController::offertevergelijker', array('data' => $fields'campaign' => 11))->getContent();
  2256.                                 break;
  2257.                             case 16// Offertevergelijker Isolatie
  2258.                                 $webservice $this->forward('App\Controller\WebserviceController::offertevergelijker', array('data' => $fields'campaign' => 16))->getContent();
  2259.                                 break;
  2260.                             case 15// Datafanatics Isolatie
  2261.                                 $webservice $this->forward('App\Controller\WebserviceController::datafanatics', array('data' => $fields'campaign' => 15))->getContent();
  2262.                                 break;
  2263.                             case 7// Datafanatics Zonnepanelen
  2264.                                 $webservice $this->forward('App\Controller\WebserviceController::datafanatics', array('data' => $fields'campaign' => 7))->getContent();
  2265.                                 break;
  2266.                             case 9// Consumind Energie
  2267.                                 $webservice $this->forward('App\Controller\WebserviceController::consumind', array('data' => $fields))->getContent();
  2268.                                 break;
  2269.                             case 4// Vente-Unique PL
  2270.                                 $webservice $this->forward('App\Controller\WebserviceController::venteuniquepl', array('data' => $fields))->getContent();
  2271.                                 break;
  2272.                             case 5// Vente-Unique PT
  2273.                                 $webservice $this->forward('App\Controller\WebserviceController::venteuniquept', array('data' => $fields))->getContent();
  2274.                                 break;
  2275.                             case 6// Vente-Unique BEFR
  2276.                                 $webservice $this->forward('App\Controller\WebserviceController::venteuniquebefr', array('data' => $fields))->getContent();
  2277.                                 break;
  2278.                             case 3// Test
  2279.                                 $webservice $this->forward('App\Controller\WebserviceController::loudingads2', array('data' => $fields'campaign' => $campaign->getId()))->getContent();
  2280.                                 break;
  2281.                         }
  2282.                         $webservice json_decode($webservice);
  2283.                         if (!isset($webservice->check)) {
  2284.                             $arraycheck[$campaign->getId()]["check"]=0;
  2285.                             $arraycheck[$campaign->getId()]["filter"]=1;
  2286.                             $response 2;
  2287.                             if ($campaign->getEmailNotification()){
  2288.                                 $to 'lennard@loudingads.com';
  2289.                                 $subject 'Error in campaign '$campaign->getId();
  2290.                                 $headers "MIME-Version: 1.0" "\r\n";
  2291.                                 $headers .= "Content-type:text/html;charset=UTF-8" "\r\n";
  2292.                                 if (!$webservice){
  2293.                                     $webservice "Uncaught Webservice";
  2294.                                 }
  2295.                                 $this->emailService->sendEmail($to,"lennard@loudingads.com"$subject$webservice$headers);
  2296.                             }
  2297.                         } else {
  2298.                             if ($webservice->check == 1) { // Lead suceessfully send to the customer and accepted
  2299.                                 $arraycheck[$campaign->getId()]["check"]=1;
  2300.                                 $arraycheck[$campaign->getId()]["filter"]=1;
  2301.                                 //$result['validcampaign'] = true;
  2302.                                 // $result['validcustomer'] = true;
  2303.                                 if ($campaign->getVariablePrice() == 1){
  2304.                                     if (isset($webservice->price)){
  2305.                                         $result['revenue'] = $result['revenue'] + $webservice->price;
  2306.                                     }else{
  2307.                                         $result['revenue'] = $result['revenue'] + $campaign->getPrice();
  2308.                                     }
  2309.                                 }else{
  2310.                                     $result['revenue'] = $result['revenue'] + $campaign->getPrice();
  2311.                                 }
  2312.                                 $result['sold'] = $result['sold'] + 1;
  2313.                                 if(str_contains($lead->getEmail(), '@loudingest.com') == false){
  2314.                                     $campaign->setGross($campaign->getGross() + 1);
  2315.                                     $campaign->setValid($campaign->getValid() + 1);
  2316.                                     if ($campaign->getVariablePrice() == 1){
  2317.                                         if (isset($webservice->price)){
  2318.                                             $campaign->setRevenue($campaign->getRevenue() + $webservice->price);
  2319.                                         }else{
  2320.                                             $campaign->setRevenue($campaign->getRevenue() + $campaign->getPrice());
  2321.                                         }
  2322.                                     }else{
  2323.                                         $campaign->setRevenue($campaign->getRevenue() + $campaign->getPrice());
  2324.                                     }
  2325.                                 }
  2326.                                 $response 1;
  2327.                             } else { // Lead rejected by the customer
  2328.                                 $arraycheck[$campaign->getId()]['check'] = 0;
  2329.                                 $arraycheck[$campaign->getId()]['filter'] = 1;
  2330.                                 $campaign->setGross($campaign->getGross() + 1);
  2331.                                 $campaign->setInvalid($campaign->getInvalid() + 1);
  2332.                                 $response 0;
  2333.                             }
  2334.                             $em->persist($campaign);
  2335.                             $em->flush();
  2336.                             // Register the call into wslog
  2337.                             $wslog = new Wslog();
  2338.                             $wslog->setCampaign($campaign);
  2339.                             $wslog->setLead($lead);
  2340.                             $wslog->setResponse($webservice->check);
  2341.                             //$wslog->setType($ws->getMethod());
  2342.                             $wslog->setFeedback($webservice->response);
  2343.                             $wslog->setTimestamp(new \Datetime('Europe/Madrid'));
  2344.                             $wslog->setWscall(json_encode($webservice->wscallJSON_UNESCAPED_SLASHES));
  2345.                             $em->persist($wslog);
  2346.                             $em->flush();
  2347.                             if ($campaign->getEmailNotification()){
  2348.                                 if(str_contains($lead->getEmail(), '@loudingest.com') == false){
  2349.                                     $this->campaignService->verifyAndSendEmail($lead,$campaign);
  2350.                                 }
  2351.                             }
  2352.                         }
  2353.                     } else { // If campaign as validation manual
  2354.                         $result['revenue'] = $result['revenue'] + $campaign->getPrice();
  2355.                         $result['sold'] = $result['sold'] + 1;
  2356.                         //$result['validcampaign'] = true;
  2357.                         $arraycheck[$campaign->getId()]['filter'] = 1;
  2358.                         //$result['validcustomer'] = true;
  2359.                         $arraycheck[$campaign->getId()]['check'] = 1;
  2360.                         $response 1// valid lead sent
  2361.                     }
  2362.                     // Set leadcampaign
  2363.                     $leadcampaign = new Leadcampaign();
  2364.                     $leadcampaign->setLead($lead);
  2365.                     $leadcampaign->setCampaign($campaign);
  2366.                     if (isset($webservice->buyerid) && $webservice->buyerid != null){
  2367.                         $leadcampaign->setBuyerid($webservice->buyerid);
  2368.                     }
  2369.                     if (isset($wslog)) {
  2370.                         $leadcampaign->setWs($wslog);
  2371.                         $leadcampaign->setReason('webservice');
  2372.                         if ($response == 1) {
  2373.                             $lc_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // valid
  2374.                             if (str_contains($lead->getEmail(), '@loudingest.com') == true){
  2375.                                 $lc_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(18);
  2376.                             } else {
  2377.                                 $campaign->setCappingReach($campaign->getCappingReach() + 1);
  2378.                                 $campaign->setDailyreach($campaign->getDailyreach() + 1);
  2379.                                 $campaign->setMonthlyreach($campaign->getMonthlyreach() + 1);
  2380.                                 $campaign->setWeeklyreach($campaign->getWeeklyreach() + 1);
  2381.                                 if ($campaign->getDailycap() == $campaign->getDailyreach() && $campaign->getDailycap() != 0){
  2382.                                     $campaignstatus $this->getDoctrine()->getRepository(Status::class)->findOneById(10);
  2383.                                     $campaign->setStatus($campaignstatus);
  2384.                                 }
  2385.                                 if ($campaign->getWeeklycapping() == $campaign->getWeeklyreach() && $campaign->getWeeklycapping() != 0){
  2386.                                     $campaignstatus $this->getDoctrine()->getRepository(Status::class)->findOneById(13);
  2387.                                     $campaign->setStatus($campaignstatus);
  2388.                                 }
  2389.                                 if ($campaign->getMonthlycap() == $campaign->getMonthlyreach() && $campaign->getMonthlycap() != 0){
  2390.                                     $campaignstatus $this->getDoctrine()->getRepository(Status::class)->findOneById(11);
  2391.                                     $campaign->setStatus($campaignstatus);
  2392.                                 }
  2393.                                 if ($campaign->getCapping() == $campaign->getCappingReach() && ($campaign->getCapping() != && $campaign->getCapping() != null)){
  2394.                                     $campaignstatus $this->getDoctrine()->getRepository(Status::class)->findOneById(12);
  2395.                                     $campaign->setStatus($campaignstatus);
  2396.                                     $campaign->setCappingReach(0);
  2397.                                 }
  2398.                             }
  2399.                             $leadcampaign->setCampaign($campaign);
  2400.                             if(str_contains($lead->getEmail(), '@loudingest.com') == false) {
  2401.                                 if ($campaign->getVariablePrice() == 1) {
  2402.                                     if (isset($webservice->price)) {
  2403.                                         $leadcampaign->setRevenue($webservice->price);
  2404.                                     } else {
  2405.                                         $leadcampaign->setRevenue($campaign->getPrice());
  2406.                                     }
  2407.                                 } else {
  2408.                                     $leadcampaign->setRevenue($campaign->getPrice());
  2409.                                 }
  2410.                             }
  2411.                             $leadcampaign->setStatus($lc_status);
  2412.                             $leadcampaign->setValidationdate(new \Datetime('Europe/Madrid'));
  2413.                         } else {
  2414.                             $lc_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(3); // invalid
  2415.                             $leadcampaign->setStatus($lc_status);
  2416.                             $leadcampaign->setValidationdate(new \Datetime('Europe/Madrid'));
  2417.                         }
  2418.                     } else { // the Campaign has no web service
  2419.                         $lc_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // active
  2420.                         $leadcampaign->setStatus($lc_status);
  2421.                         if (str_contains($lead->getEmail(), '@loudingest.com') != true){
  2422.                             $campaign->setCappingReach($campaign->getCappingReach() + 1);
  2423.                             $campaign->setDailyreach($campaign->getDailyreach() + 1);
  2424.                             $campaign->setMonthlyreach($campaign->getMonthlyreach() + 1);
  2425.                             $campaign->setWeeklyreach($campaign->getWeeklyreach() + 1);
  2426.                             if ($campaign->getDailycap() == $campaign->getDailyreach() && $campaign->getDailycap() != 0){
  2427.                                 $campaignstatus $this->getDoctrine()->getRepository(Status::class)->findOneById(10);
  2428.                                 $campaign->setStatus($campaignstatus);
  2429.                             }
  2430.                             if ($campaign->getWeeklycapping() == $campaign->getWeeklyreach() && $campaign->getWeeklycapping() != 0){
  2431.                                 $campaignstatus $this->getDoctrine()->getRepository(Status::class)->findOneById(13);
  2432.                                 $campaign->setStatus($campaignstatus);
  2433.                             }
  2434.                             if ($campaign->getMonthlycap() == $campaign->getMonthlyreach() && $campaign->getMonthlycap() != 0){
  2435.                                 $campaignstatus $this->getDoctrine()->getRepository(Status::class)->findOneById(11);
  2436.                                 $campaign->setStatus($campaignstatus);
  2437.                             }
  2438.                             if ($campaign->getCapping() == $campaign->getCappingReach() && ($campaign->getCapping() != && $campaign->getCapping() != null)){
  2439.                                 $campaignstatus $this->getDoctrine()->getRepository(Status::class)->findOneById(12);
  2440.                                 $campaign->setStatus($campaignstatus);
  2441.                                 $campaign->setCappingReach(0);
  2442.                             }
  2443.                         }
  2444.                     }
  2445.                     $leadcampaign->setCurrency($campaign->getCurrency());
  2446.                     $leadcampaign->setRegistrationdate(new \Datetime('Europe/Madrid'));
  2447.                     $em->persist($leadcampaign);
  2448.                     $em->flush();
  2449.                 }
  2450.             } else { // filter campaign not passed
  2451.                 $arraycheck[$campaign->getId()]['filter'] = 0;
  2452.                 $arraycheck[$campaign->getId()]['check'] = 0;
  2453.             }
  2454.             if($response == 1) { // Customer accepted the lead
  2455.                 $c++;
  2456.             }
  2457.             if($this->testlead !== true || $this->testwebservice !== true) { // exclusivity only for test
  2458.                 //if($this->testlead !== true || $this->testwebservice !== true) { // don't apply exclusivity for test: the lead is sent to all the campaigns in test status
  2459.                 //if($testlead !== true && $testwebservice !== true) { // don't apply exclusivity for test: the lead is sent to all the campaigns in test status
  2460.                 if($c $exclusivity) { // already reach the maximum number of lead to share
  2461.                     break;
  2462.                 }
  2463.             }
  2464.         }
  2465.         // Set up the response array values
  2466.         if(isset($arraycheck)){
  2467.             $checkOne array_filter($arraycheck, function ($element) {
  2468.                 return isset($element['check']) && $element['check'] === 1;
  2469.             });
  2470.             if (!empty($checkOne)) {
  2471.                 $result['validcustomer'] = true;
  2472.             }else{
  2473.                 $result['validcustomer'] = false;
  2474.             }
  2475.             $checkTwo array_filter($arraycheck, function ($element) {
  2476.                 return isset($element['filter']) && $element['filter'] === 1;
  2477.             });
  2478.             if (!empty($checkTwo)) {
  2479.                 $result['validcampaign'] = true;
  2480.             }else{
  2481.                 $result['validcampaign'] = false;
  2482.             }
  2483.         }
  2484.         return $result;
  2485.     }
  2486.     public function leadfield($fields$data$lead)
  2487.     {
  2488.         foreach ($fields as $field) {
  2489.             $fieldname $field->getName();
  2490.             if (isset($data[$fieldname])) {
  2491.                 $leadfield $this->insertleadfield($lead$field$data[$fieldname]);
  2492.             }
  2493.         }
  2494.         return 1;
  2495.     }
  2496.     public function checkfilter($lead) { // Check if lead passes project filters
  2497.         $active $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
  2498.         $project $lead->getProject();
  2499.         // Get all Filtergroup for this project
  2500.         $filtersgroup $this->getDoctrine()->getRepository(Filtergroup::class)->findBy(array(
  2501.                 'project' => $project,
  2502.                 'status' => $active
  2503.             )
  2504.         );
  2505.         if (count($filtersgroup) > 0) { // check if there are any Filtergroup active
  2506.             foreach ($filtersgroup as $filtergroup) {
  2507.                 $check = array();
  2508.                 $i 0;
  2509.                 foreach ($filtergroup->getFilters() as $filter) { // Get all Filters from Filtergroup
  2510.                     $field $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(array(
  2511.                             'lead' => $lead,
  2512.                             'field' => $filter->getField()
  2513.                         )
  2514.                     );
  2515.                     if($field !== null) {
  2516.                         $value $field->getValue();
  2517.                     } else {
  2518.                         $value null;
  2519.                     }
  2520.                     /*if ($field == null) {
  2521.                         return false;
  2522.                     } else {
  2523.                         $value = $field->getValue();
  2524.                     }*/
  2525.                     $filteroperator $filter->getOperator()->getId();
  2526.                     $filtervalue $filter->getValue();
  2527.                     $check[$i] = 0// Condition false by default
  2528.                     //switch
  2529.                     if ($filteroperator == 1) { // equal
  2530.                         if ($value == $filtervalue) {
  2531.                             $check[$i] = true;
  2532.                         } else {
  2533.                             $check[$i] = false;
  2534.                         }
  2535.                     } elseif ($filteroperator == 2) { // not equal
  2536.                         if ($value !== $filtervalue) {
  2537.                             $check[$i] = true;
  2538.                         } else {
  2539.                             $check[$i] = false;
  2540.                         }
  2541.                     } elseif ($filteroperator == 3) { // contains
  2542.                         if (strpos($value$filtervalue) !== false) {
  2543.                             $check[$i] = true;
  2544.                         } else {
  2545.                             $check[$i] = false;
  2546.                         }
  2547.                     } elseif ($filteroperator == 4) { // not contains
  2548.                         if (!strpos($value$filtervalue) !== false) {
  2549.                             $check[$i] = true;
  2550.                         } else {
  2551.                             $check[$i] = false;
  2552.                         }
  2553.                     } elseif ($filteroperator == 5) { // =
  2554.                         if (is_numeric($value) && $value == $filtervalue) {
  2555.                             $check[$i] = true;
  2556.                         } else {
  2557.                             $check[$i] = false;
  2558.                         }
  2559.                     } elseif ($filteroperator == 6) { // !=
  2560.                         if (is_numeric($value) && $value !== $filtervalue) {
  2561.                             $check[$i] = true;
  2562.                         } else {
  2563.                             $check[$i] = false;
  2564.                         }
  2565.                     } elseif ($filteroperator == 7) { // >
  2566.                         if ($value $filtervalue) {
  2567.                             $check[$i] = true;
  2568.                         } else {
  2569.                             $check[$i] = false;
  2570.                         }
  2571.                     } elseif ($filteroperator == 8) { // >=
  2572.                         if ($value >= $filtervalue) {
  2573.                             $check[$i] = true;
  2574.                         } else {
  2575.                             $check[$i] = false;
  2576.                         }
  2577.                     } elseif ($filteroperator == 9) { // <
  2578.                         if ($value $filtervalue) {
  2579.                             $check[$i] = true;
  2580.                         } else {
  2581.                             $check[$i] = false;
  2582.                         }
  2583.                     } elseif ($filteroperator == 10) { // <=
  2584.                         if ($value <= $filtervalue) {
  2585.                             $check[$i] = true;
  2586.                         } else {
  2587.                             $check[$i] = false;
  2588.                         }
  2589.                     } elseif ($filteroperator == 11) { // =  - date
  2590.                         if ($value == $filtervalue) {
  2591.                             $check[$i] = true;
  2592.                         } else {
  2593.                             $check[$i] = false;
  2594.                         }
  2595.                     } elseif ($filteroperator == 12) { // !=  - date
  2596.                         if ($value !== $filtervalue) {
  2597.                             $check[$i] = true;
  2598.                         } else {
  2599.                             $check[$i] = false;
  2600.                         }
  2601.                     } elseif ($filteroperator == 13) { // >  - date
  2602.                         if ($value $filtervalue) {
  2603.                             $check[$i] = true;
  2604.                         } else {
  2605.                             $check[$i] = false;
  2606.                         }
  2607.                     } elseif ($filteroperator == 14) { // >=  - date
  2608.                         if ($value >= $filtervalue) {
  2609.                             $check[$i] = true;
  2610.                         } else {
  2611.                             $check[$i] = false;
  2612.                         }
  2613.                     } elseif ($filteroperator == 15) { // <  - date
  2614.                         if ($value $filtervalue) {
  2615.                             $check[$i] = true;
  2616.                         } else {
  2617.                             $check[$i] = false;
  2618.                         }
  2619.                     } elseif ($filteroperator == 16) { // <=  - date
  2620.                         if ($value <= $filtervalue) {
  2621.                             $check[$i] = true;
  2622.                         } else {
  2623.                             $check[$i] = false;
  2624.                         }
  2625.                     } elseif ($filteroperator == 17) { // older than  - date
  2626.                         $filtervalue strtotime('- ' $filtervalue ' year');
  2627.                         $value strtotime($value);
  2628.                         if ($value <= $filtervalue) {
  2629.                             $check[$i] = true;
  2630.                         } else {
  2631.                             $check[$i] = false;
  2632.                         }
  2633.                     } elseif ($filteroperator == 18) { // younger than  - date
  2634.                         $filtervalue strtotime('- ' $filtervalue ' year');
  2635.                         $value strtotime($value);
  2636.                         if ($value >= $filtervalue) {
  2637.                             $check[$i] = true;
  2638.                         } else {
  2639.                             $check[$i] = false;
  2640.                         }
  2641.                     } elseif ($filteroperator == 19) { // starts with - string - case insensitive
  2642.                         if (str_starts_with(strtolower($value), strtolower($filtervalue)) !== false) {
  2643.                             $check[$i] = true;
  2644.                         } else {
  2645.                             $check[$i] = false;
  2646.                         }
  2647.                     } elseif ($filteroperator == 20) { // ends with - string
  2648.                         if (str_ends_with(strtolower($value), strtolower($filtervalue)) !== false) {
  2649.                             $check[$i] = true;
  2650.                         } else {
  2651.                             $check[$i] = false;
  2652.                         }
  2653.                     } elseif ($filteroperator == 21) { // hour before than  - datetime
  2654.                         $value substr($value,11,2);
  2655.                         if ($value $filtervalue) {
  2656.                             $check[$i] = true;
  2657.                         } else {
  2658.                             $check[$i] = false;
  2659.                         }
  2660.                     } elseif ($filteroperator == 22) { // hour later than  - datetime
  2661.                         $value substr($value,11,2);
  2662.                         if ($value >= $filtervalue) {
  2663.                             $check[$i] = true;
  2664.                         } else {
  2665.                             $check[$i] = false;
  2666.                         }
  2667.                     } elseif ($filteroperator == 23 || $filteroperator == 29) { // day of the week equal
  2668.                         $filtervalue strtolower($filtervalue);
  2669.                         if ($filtervalue == strtolower(date('l')) || $filtervalue == strtolower(date('D'))) {
  2670.                             $check[$i] = true;
  2671.                         } else {
  2672.                             $check[$i] = false;
  2673.                         }
  2674.                     } elseif ($filteroperator == 24 || $filteroperator == 30) { // day of the week different
  2675.                         $filtervalue strtolower($filtervalue);
  2676.                         if ($filtervalue != strtolower(date('l')) && $filtervalue != strtolower(date('D'))) {
  2677.                             $check[$i] = true;
  2678.                         } else {
  2679.                             $check[$i] = false;
  2680.                         }
  2681.                     } elseif ($filteroperator == 27) { // is empty
  2682.                         if($value == '' || $value == null) {
  2683.                             $check[$i] = true;
  2684.                         } else {
  2685.                             $check[$i] = false;
  2686.                         }
  2687.                     } elseif ($filteroperator == 28) { // is not empty
  2688.                         if($value !== '' && $value !== null) {
  2689.                             $check[$i] = true;
  2690.                         } else {
  2691.                             $check[$i] = false;
  2692.                         }
  2693.                     }
  2694.                     $i++;
  2695.                 }
  2696.                 $boolean $filtergroup->getBoolean();
  2697.                 if ($boolean == 0) { // all check must be true
  2698.                     if (in_array(false$check)) {
  2699.                         $filtercheck false;
  2700.                     } else {
  2701.                         $filtercheck true;
  2702.                     }
  2703.                 } elseif ($boolean == 1) { // at least one check must be true
  2704.                     if (in_array(true$check)) {
  2705.                         $filtercheck true;
  2706.                     } else {
  2707.                         $filtercheck false;
  2708.                     }
  2709.                 } elseif ($boolean == 2) { // all check must be false
  2710.                     if (in_array(true$check)) {
  2711.                         $filtercheck false;
  2712.                     } else {
  2713.                         $filtercheck true;
  2714.                     }
  2715.                 }
  2716.                 try {
  2717.                     $report = new ProjectFilterLog();
  2718.                     $report->setLead($lead);
  2719.                     $report->setFiltergroup($filtergroup);
  2720.                     $report->setResult($filtercheck);
  2721.                     $report->setDate(time());
  2722.                     $em $this->getDoctrine()->getManager();
  2723.                     $em->persist($report);
  2724.                     $em->flush();
  2725.                 }catch(\Exception $e){
  2726.                 }
  2727.                 if ($filtercheck == false) { // If only one filtergroup is false the loop blocks and return false
  2728.                     return $filtercheck;
  2729.                 }
  2730.             }
  2731.         } else { // No Filtergroup active
  2732.             $filtercheck true;
  2733.         }
  2734.         return $filtercheck;
  2735.     }
  2736.     public function checkcampaignfilter($lead$campaign)
  2737.     {
  2738.         try {
  2739.             $active $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
  2740.             $filtersgroup $this->getDoctrine()->getRepository(Filtercampaigngroup::class)->findBy(array(
  2741.                     'campaign' => $campaign,
  2742.                     'status' => $active
  2743.                 )
  2744.             );
  2745.             $project $lead->getProject();
  2746.             if (count($filtersgroup) > 0) {
  2747.                 foreach ($filtersgroup as $fg) {
  2748.                     $check = array();
  2749.                     $i 0;
  2750.                     foreach ($fg->getFilters() as $filter) {
  2751.                         $fieldcampaign $filter->getFieldcampaign();
  2752.                         $repository $this->getDoctrine()->getRepository(Field::class);
  2753.                         $query $repository->createQueryBuilder('c');
  2754.                         $query->addSelect('c');
  2755.                         $query->andWhere(':fieldcampaign MEMBER OF c.fieldcampaigns');
  2756.                         $query->setParameter('fieldcampaign'$fieldcampaign->getId());
  2757.                         $query->andWhere('c.project = :project');
  2758.                         $query->setParameter('project'$project->getId());
  2759.                         $query $query->getQuery();
  2760.                         $field $query->getResult();
  2761.                         $value $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(array(
  2762.                                 'lead' => $lead,
  2763.                                 'field' => $field[0]
  2764.                             )
  2765.                         );
  2766.                         if ($value == null) {
  2767.                             $report = new Campaignfilterlog();
  2768.                             $report->setLead($lead);
  2769.                             $report->setFiltergroup($fg);
  2770.                             $report->setResult(false);
  2771.                             $report->setDate(time());
  2772.                             $em $this->getDoctrine()->getManager();
  2773.                             $em->persist($report);
  2774.                             $em->flush();
  2775.                             return false;
  2776.                         } else {
  2777.                             $value $value->getValue();
  2778.                         }
  2779.                         $filteroperator $filter->getOperator()->getId();
  2780.                         $filtervalue $filter->getValue();
  2781.                         $check[$i] = 0// Condition false by default
  2782.                         //Better to use a switch?
  2783.                         if ($filteroperator == 1) { // equal - string
  2784.                             if (strtolower($value) == strtolower($filtervalue)) {
  2785.                                 $check[$i] = true;
  2786.                             } else {
  2787.                                 $check[$i] = false;
  2788.                             }
  2789.                         } elseif ($filteroperator == 2) { // not equal - string
  2790.                             if (strtolower($value) !== strtolower($filtervalue)) {
  2791.                                 $check[$i] = true;
  2792.                             } else {
  2793.                                 $check[$i] = false;
  2794.                             }
  2795.                         } elseif ($filteroperator == 3) { // contains - string
  2796.                             if (strpos($value$filtervalue) !== false) {
  2797.                                 $check[$i] = true;
  2798.                             } else {
  2799.                                 $check[$i] = false;
  2800.                             }
  2801.                         } elseif ($filteroperator == 4) { // not contains - string
  2802.                             if (!strpos($value$filtervalue) !== false) {
  2803.                                 $check[$i] = true;
  2804.                             } else {
  2805.                                 $check[$i] = false;
  2806.                             }
  2807.                         } elseif ($filteroperator == 19) { // starts with - string
  2808.                             $value str_replace(' ','',$value); // replace white spaces
  2809.                             if (str_starts_with(strtolower($value), strtolower($filtervalue)) !== false) {
  2810.                                 $check[$i] = true;
  2811.                             } else {
  2812.                                 $check[$i] = false;
  2813.                             }
  2814.                         } elseif ($filteroperator == 20) { // ends with - string
  2815.                             $value str_replace(' ','',$value); // replace white spaces
  2816.                             if (str_ends_with(strtolower($value), strtolower($filtervalue)) !== false) {
  2817.                                 $check[$i] = true;
  2818.                             } else {
  2819.                                 $check[$i] = false;
  2820.                             }
  2821.                         } elseif ($filteroperator == 5) { // =  - number
  2822.                             if (is_numeric($value) && $value == $filtervalue) {
  2823.                                 $check[$i] = true;
  2824.                             } else {
  2825.                                 $check[$i] = false;
  2826.                             }
  2827.                         } elseif ($filteroperator == 6) { // !=  - number
  2828.                             if (is_numeric($value) && $value !== $filtervalue) {
  2829.                                 $check[$i] = true;
  2830.                             } else {
  2831.                                 $check[$i] = false;
  2832.                             }
  2833.                         } elseif ($filteroperator == 7) { // >  - number
  2834.                             if ($value $filtervalue) {
  2835.                                 $check[$i] = true;
  2836.                             } else {
  2837.                                 $check[$i] = false;
  2838.                             }
  2839.                         } elseif ($filteroperator == 8) { // >=  - number
  2840.                             if ($value >= $filtervalue) {
  2841.                                 $check[$i] = true;
  2842.                             } else {
  2843.                                 $check[$i] = false;
  2844.                             }
  2845.                         } elseif ($filteroperator == 9) { // <  - number
  2846.                             if ($value $filtervalue) {
  2847.                                 $check[$i] = true;
  2848.                             } else {
  2849.                                 $check[$i] = false;
  2850.                             }
  2851.                         } elseif ($filteroperator == 10) { // <=  - number
  2852.                             if ($value <= $filtervalue) {
  2853.                                 $check[$i] = true;
  2854.                             } else {
  2855.                                 $check[$i] = false;
  2856.                             }
  2857.                         } elseif ($filteroperator == 11) { // =  - date
  2858.                             if ($value == $filtervalue) {
  2859.                                 $check[$i] = true;
  2860.                             } else {
  2861.                                 $check[$i] = false;
  2862.                             }
  2863.                         } elseif ($filteroperator == 12) { // !=  - date
  2864.                             if ($value !== $filtervalue) {
  2865.                                 $check[$i] = true;
  2866.                             } else {
  2867.                                 $check[$i] = false;
  2868.                             }
  2869.                         } elseif ($filteroperator == 13) { // >  - date
  2870.                             if ($value $filtervalue) {
  2871.                                 $check[$i] = true;
  2872.                             } else {
  2873.                                 $check[$i] = false;
  2874.                             }
  2875.                         } elseif ($filteroperator == 14) { // >=  - date
  2876.                             if ($value >= $filtervalue) {
  2877.                                 $check[$i] = true;
  2878.                             } else {
  2879.                                 $check[$i] = false;
  2880.                             }
  2881.                         } elseif ($filteroperator == 15) { // <  - date
  2882.                             if ($value $filtervalue) {
  2883.                                 $check[$i] = true;
  2884.                             } else {
  2885.                                 $check[$i] = false;
  2886.                             }
  2887.                         } elseif ($filteroperator == 16) { // <=  - date
  2888.                             if ($value <= $filtervalue) {
  2889.                                 $check[$i] = true;
  2890.                             } else {
  2891.                                 $check[$i] = false;
  2892.                             }
  2893.                         } elseif ($filteroperator == 17) { // older than  - date
  2894.                             $filtervalue strtotime('- ' $filtervalue ' year');
  2895.                             $value strtotime($value);
  2896.                             ;
  2897.                             if ($value <= $filtervalue) {
  2898.                                 $check[$i] = true;
  2899.                             } else {
  2900.                                 $check[$i] = false;
  2901.                             }
  2902.                         } elseif ($filteroperator == 18) { // younger than  - date
  2903.                             $filtervalue strtotime('- ' $filtervalue ' year');
  2904.                             $value strtotime($value);
  2905.                             if ($value >= $filtervalue) {
  2906.                                 $check[$i] = true;
  2907.                             } else {
  2908.                                 $check[$i] = false;
  2909.                             }
  2910.                         }
  2911.                         elseif ($filteroperator == 21) { // hour before than  - datetime
  2912.                             $value substr($value,11,2);
  2913.                             if ($value $filtervalue) {
  2914.                                 $check[$i] = true;
  2915.                             } else {
  2916.                                 $check[$i] = false;
  2917.                             }
  2918.                         }
  2919.                         elseif ($filteroperator == 22) { // hour later than  - datetime
  2920.                             $value substr($value,11,2);
  2921.                             if ($value >= $filtervalue) {
  2922.                                 $check[$i] = true;
  2923.                             } else {
  2924.                                 $check[$i] = false;
  2925.                             }
  2926.                         }
  2927.                         elseif ($filteroperator == 23 || $filteroperator == 29) { // day of the week equal
  2928.                             $filtervalue strtolower($filtervalue);
  2929.                             if ($filtervalue == strtolower(date('l')) || $filtervalue == strtolower(date('D'))) {
  2930.                                 $check[$i] = true;
  2931.                             } else {
  2932.                                 $check[$i] = false;
  2933.                             }
  2934.                         }
  2935.                         elseif ($filteroperator == 24 || $filteroperator == 30) { // day of the week different
  2936.                             date_default_timezone_set("Europe/Madrid");
  2937.                             $filtervalue strtolower($filtervalue);
  2938.                             if ($filtervalue !== strtolower(date('l')) && $filtervalue !== strtolower(date('D'))) {
  2939.                                 $check[$i] = true;
  2940.                             } else {
  2941.                                 $check[$i] = false;
  2942.                             }
  2943.                         }
  2944.                         elseif ($filteroperator == 25) { // equal file
  2945.                             $file $this->getParameter('filefilter_directory')."/".$filtervalue;
  2946.                             $fp fopen($file,'r') or die("Can't open the file");
  2947.                             while($line fgets($fp)) {
  2948.                                 /*  $find = array("\n", ",");
  2949.                                   $line = str_replace($find,"",$line);
  2950.                                   if (is_numeric($line)){*/
  2951.                                 $line str_replace("\n","",$line);
  2952.                                 $filevalues[] = strtolower($line);
  2953.                                 /*                }
  2954.                                 */
  2955.                             }
  2956.                             if (in_array(strtolower($value),$filevalues)) {
  2957.                                 $check[$i] = true;
  2958.                             } else {
  2959.                                 $check[$i] = false;
  2960.                             }
  2961.                             fclose($fp) or die("Error closing the file");
  2962.                         }
  2963.                         elseif ($filteroperator == 26) { // not equal file
  2964.                             $file $this->getParameter('filefilter_directory')."/".$filtervalue;
  2965.                             $fp fopen($file,'r') or die("Can't open the file");
  2966.                             while($line fgets($fp)) {
  2967.                                 /*  $find = array("\n", ",");
  2968.                                   $line = str_replace($find,"",$line);
  2969.                                   if (is_numeric($line)){*/
  2970.                                 $line str_replace("\n","",$line);
  2971.                                 $filevalues[] = strtolower($line);
  2972.                                 /*                }
  2973.                                 */
  2974.                             }
  2975.                             if (!in_array(strtolower($value),$filevalues)) {
  2976.                                 $check[$i] = true;
  2977.                             } else {
  2978.                                 $check[$i] = false;
  2979.                             }
  2980.                             fclose($fp) or die("Error closing the file");
  2981.                         }
  2982.                         elseif ($filteroperator == 31) { // starts file with - string
  2983.                             $file $this->getParameter('filefilter_directory')."/".$filtervalue;
  2984.                             $fp fopen($file,'r') or die("Can't open the file");
  2985.                             $check[$i] = false;
  2986.                             while($line fgets($fp) and $check[$i] == false) {
  2987.                                 /*  $find = array("\n", ",");
  2988.                                   $line = str_replace($find,"",$line);
  2989.                                   if (is_numeric($line)){*/
  2990.                                 $line str_replace("\n","",$line);
  2991.                                 $filevalues[] = strtolower($line);
  2992.                                 if (str_starts_with(strtolower($value), strtolower($line)) !== false) {
  2993.                                     $check[$i] = true;
  2994.                                 }
  2995.                             
  2996.                             }
  2997.                             
  2998.                             fclose($fp) or die("Error closing the file");
  2999.                         }
  3000.                         $i++;
  3001.                     }
  3002.                     $boolean $fg->getBoolean();
  3003.                     if ($boolean == 0) { // all check must be true
  3004.                         if (in_array(false$check)) {
  3005.                             $filtercheck false;
  3006.                         } else {
  3007.                             $filtercheck true;
  3008.                         }
  3009.                     } elseif ($boolean == 1) { // at least one check must be true
  3010.                         if (in_array(true$check)) {
  3011.                             $filtercheck true;
  3012.                         } else {
  3013.                             $filtercheck false;
  3014.                         }
  3015.                     } elseif ($boolean == 2) { // all check must be false
  3016.                         if (in_array(true$check)) {
  3017.                             $filtercheck false;
  3018.                         } else {
  3019.                             $filtercheck true;
  3020.                         }
  3021.                     }
  3022.                     $report = new Campaignfilterlog();
  3023.                     $report->setLead($lead);
  3024.                     $report->setFiltergroup($fg);
  3025.                     $report->setResult($filtercheck);
  3026.                     $report->setDate(time());
  3027.                     $em $this->getDoctrine()->getManager();
  3028.                     $em->persist($report);
  3029.                     $em->flush();
  3030.                     if ($filtercheck == false) { // If only one filtergroup is false the loop blocks and return false
  3031.                         return $filtercheck;
  3032.                     }
  3033.                 }
  3034.             } else {
  3035.                 $filtercheck true;
  3036.             }
  3037.         }catch(\Exception $e){
  3038.             $filtercheck false;
  3039.         }
  3040.         return $filtercheck;
  3041.     }
  3042.     public function checkleadfield($fields$data$lead)
  3043.     {
  3044.         foreach ($fields as $field) {
  3045.             $fieldname $field->getName();
  3046.             if ($field->getMandatory() == 1) {
  3047.                 if (isset($data[$fieldname])) {
  3048.                     if ($data[$fieldname] !== null && $data[$fieldname] !== '') {
  3049.                         $validator[] = $this->validator($data[$fieldname], $field);
  3050.                         //$leadfield = $this->leadfield($lead,$field,$data[$fieldname]);
  3051.                     } else {
  3052.                         $validator[] = false;
  3053.                         //$leadfield = $this->leadfield($lead,$field,$data[$fieldname]);
  3054.                     }
  3055.                 }
  3056.             } else {
  3057.                 if (!isset($data[$fieldname])) {
  3058.                     $data[$fieldname] = null;
  3059.                 }
  3060.                 $validator[] = true;
  3061.             }
  3062.             //var_dump($data[$fieldname]);
  3063.             $leadfield $this->insertleadfield($lead$field$data[$fieldname]);
  3064.         }
  3065.         return $validator;
  3066.     }
  3067.     public function insertleadfield($lead$field$data)
  3068.     {
  3069.         $em $this->getDoctrine()->getManager();
  3070.         // Insert leadfields
  3071.         $leadfield = new Leadfield();
  3072.         $leadfield->setLead($lead);
  3073.         $leadfield->setField($field);
  3074.         $leadfield->setValue($data);
  3075.         $em->persist($leadfield);
  3076.         $em->flush();
  3077.     }
  3078.     public function insertlead($data$project$lead_status)
  3079.     {
  3080.         $em $this->getDoctrine()->getManager();
  3081.         // Mapping data
  3082.         if (isset($data['email'])) {
  3083.             $email $data['email'];
  3084.         } else {
  3085.             $email null;
  3086.         }
  3087.         if (isset($data['session'])) {
  3088.             //$session = $data['session'];
  3089.             $session $this->getDoctrine()->getRepository(Session::class)->findOneById($data['session']);
  3090.         } else {
  3091.             $session null;
  3092.         }
  3093.         if (isset($data['phone'])) {
  3094.             $phone $data['phone'];
  3095.         } else {
  3096.             $phone null;
  3097.         }
  3098.         if (isset($data['ip'])) {
  3099.             $ip $data['ip'];
  3100.         } else {
  3101.             $ip null;
  3102.         }
  3103.         if (isset($data['client'])) {
  3104.             $client $data['client'];
  3105.         } else {
  3106.             $client null;
  3107.         }
  3108.         if (isset($data['referral'])) {
  3109.             $referral $data['referral'];
  3110.         } else {
  3111.             $referral null;
  3112.         }
  3113.         if (isset($data['source']) && $data['source'] !== '') {
  3114.             $source $data['source'];
  3115.         } else {
  3116.             $source null;
  3117.         }
  3118.         if (isset($data['sub1']) && $data['sub1'] !== '') {
  3119.             $sub1 $data['sub1'];
  3120.         } else {
  3121.             $sub1 null;
  3122.         }
  3123.         if (isset($data['sub2']) && $data['sub2'] !== '') {
  3124.             $sub2 $data['sub2'];
  3125.         } else {
  3126.             $sub2 null;
  3127.         }
  3128.         if (isset($data['sub3']) && $data['sub3'] !== '') {
  3129.             $sub3 $data['sub3'];
  3130.         } else {
  3131.             $sub3 null;
  3132.         }
  3133.         if (isset($data['sub4']) && $data['sub4'] !== '') {
  3134.             $sub4 $data['sub4'];
  3135.         } else {
  3136.             $sub4 null;
  3137.         }
  3138.         if (isset($data['clickid']) && $data['clickid'] !== '') {
  3139.             $clickid $data['clickid'];
  3140.         } else {
  3141.             $clickid null;
  3142.         }
  3143.         if (isset($data['offer']) && $data['offer'] !== '') {
  3144.             $offer $data['offer'];
  3145.         } else {
  3146.             $offer null;
  3147.         }
  3148.         if (isset($data['registrationdate']) && $data['registrationdate'] !== '') {
  3149.             $registrationdate = new \Datetime('Europe/Madrid');
  3150.         } else {
  3151.             $registrationdate = new \Datetime();
  3152.             $registrationdate->setTimezone(new \DateTimeZone('Europe/Madrid'));
  3153.         }
  3154.         // Insert tracking
  3155.         if ($project->getTracking() !== null && $project->getTracking()->getId() !== 2  ) {
  3156.             $tracking = new Hasoffers;
  3157.             $tracking->setClickid($clickid);
  3158.             $tracking->setOffer($offer);
  3159.             $tracking->setSource($source);
  3160.             $em->persist($tracking);
  3161.             $em->flush();
  3162.         } else {
  3163.             $tracking null;
  3164.         }
  3165.         // Create the Lead with basic data
  3166.         $lead = new Lead();
  3167.         $lead->setEmail($email);
  3168.         $lead->setPhone($phone);
  3169.         $lead->setSession($session);
  3170.         $lead->setIp($ip);
  3171.         $lead->setClient($client);
  3172.         $lead->setReferral($referral);
  3173.         $lead->setSource($source);
  3174.         $lead->setSub1($sub1);
  3175.         $lead->setSub2($sub2);
  3176.         $lead->setSub3($sub3);
  3177.         $lead->setSub4($sub4);
  3178.         $lead->setProject($project);
  3179.         $lead->setRegistrationdate(new \Datetime('Europe/Madrid'));
  3180.         $lead->setStatus($lead_status);
  3181.         $lead->setHs($tracking);
  3182.         $em->persist($lead);
  3183.         $em->flush();
  3184.         return $lead;
  3185.     }
  3186.     public function feedback($resultin$resultout$lead null$price 0)
  3187.     {
  3188.         if (isset($resultin['honeypot'])){
  3189.             if ($resultin['honeypot'] == true) {
  3190.                 $feedback = array(
  3191.                     'code' => 404,
  3192.                     'success' => false,
  3193.                     'message' => 'invalid user',
  3194.                     'lead id' => $lead->getId()
  3195.                 );
  3196.                 return $feedback;
  3197.             }
  3198.         }
  3199.         if (isset($resultin['novalidproject'])) {
  3200.             if ($resultin['novalidproject'] == true) {
  3201.                 $feedback = array(
  3202.                     'code' => 404,
  3203.                     'success' => false,
  3204.                     'message' => 'id not passed or project doesn\'t exist',
  3205.                     //'lead id' => $lead->getId()
  3206.                 );
  3207.                 return $feedback;
  3208.             }
  3209.         }
  3210.         if (isset($resultin['inactive'])) {
  3211.             if ($resultin['inactive'] == true) {
  3212.                 $feedback = array(
  3213.                     'code' => 404,
  3214.                     'success' => false,
  3215.                     'message' => 'campaign not active',
  3216.                     //'lead id' => $lead->getId()
  3217.                 );
  3218.                 return $feedback;
  3219.             }
  3220.         }
  3221.         if (isset($resultin['invalidemail'])) {
  3222.             if ($resultin['invalidemail'] == true) {
  3223.                 $feedback = array(
  3224.                     'code' => 404,
  3225.                     'success' => false,
  3226.                     'message' => 'invalid email address',
  3227.                     'lead id' => $lead->getId()
  3228.                 );
  3229.                 return $feedback;
  3230.             }
  3231.         }
  3232.         if (isset($resultin['invaliddomain'])) {
  3233.             if ($resultin['invaliddomain'] == true) {
  3234.                 $feedback = array(
  3235.                     'code' => 404,
  3236.                     'success' => false,
  3237.                     'message' => 'invalid user',
  3238.                     'lead id' => $lead->getId()
  3239.                 );
  3240.                 return $feedback;
  3241.             }
  3242.         }
  3243.         if (isset($resultin['duplicategen'])) {
  3244.             if ($resultin['duplicategen'] == true) {
  3245.                 $feedback = array(
  3246.                     'code' => 404,
  3247.                     'success' => false,
  3248.                     'message' => 'duplicate user',
  3249.                     'lead id' => $lead->getId()
  3250.                 );
  3251.                 return $feedback;
  3252.             }
  3253.         }
  3254.         if (isset($resultin['api_project'])) {
  3255.             if ($resultin['api_project'] == true) {
  3256.                 $feedback = array(
  3257.                     'code' => 404,
  3258.                     'success' => false,
  3259.                     'message' => 'permission denied',
  3260.                 );
  3261.                 return $feedback;
  3262.             }
  3263.         }
  3264.         if (isset($resultin['duplicate'])) {
  3265.             if ($resultin['duplicate'] == true) {
  3266.                 $feedback = array(
  3267.                     'code' => 404,
  3268.                     'success' => false,
  3269.                     'message' => 'duplicate user',
  3270.                     'lead id' => $lead->getId()
  3271.                 );
  3272.                 return $feedback;
  3273.             }
  3274.         }
  3275.         if (isset($resultin['duplicateemailproject'])) {
  3276.             if ($resultin['duplicateemailproject'] == true) {
  3277.                 $feedback = array(
  3278.                     'code' => 404,
  3279.                     'success' => false,
  3280.                     'message' => 'duplicate user',
  3281.                     'lead id' => $lead->getId()
  3282.                 );
  3283.                 return $feedback;
  3284.             }
  3285.         }
  3286.         if (isset($resultin['duplicateemailproject'])) {
  3287.             if ($resultin['blacklist'] == true) {
  3288.                 $feedback = array(
  3289.                     'code' => 404,
  3290.                     'success' => false,
  3291.                     'message' => 'blacklisted user',
  3292.                     'lead id' => $lead->getId()
  3293.                 );
  3294.                 return $feedback;
  3295.             }
  3296.         }
  3297.         if (isset($resultin['fake'])) {
  3298.             if ($resultin['fake'] == true) {
  3299.                 $feedback = array(
  3300.                     'code' => 404,
  3301.                     'success' => false,
  3302.                     'message' => 'invalid user',
  3303.                     'lead id' => $lead->getId()
  3304.                 );
  3305.                 return $feedback;
  3306.             }
  3307.         }
  3308.         if (isset($resultin['validproject'])) {
  3309.             if ($resultin['validproject'] == false) {
  3310.                 $feedback = array(
  3311.                     'code' => 404,
  3312.                     'success' => false,
  3313.                     'message' => 'some parameters don\'t match the target',
  3314.                     'lead id' => $lead->getId()
  3315.                 );
  3316.                 return $feedback;
  3317.             }
  3318.         }
  3319.         if (isset($resultin['inserted'])) {
  3320.             if ($resultin['inserted'] == false) {
  3321.                 $feedback = array(
  3322.                     'code' => 404,
  3323.                     'success' => false,
  3324.                     'message' => 'invalid user',
  3325.                     //'lead id' => $lead->getId()
  3326.                 );
  3327.                 return $feedback;
  3328.             }
  3329.         }
  3330.         if (isset($resultin['roifail'])) {
  3331.             if ($resultin['roifail'] == true) {
  3332.                 $feedback = array(
  3333.                     'code' => 404,
  3334.                     'success' => false,
  3335.                     'message' => 'invalid user',
  3336.                     //'lead id' => $lead->getId()
  3337.                 );
  3338.                 if (isset($lead)){
  3339.                     $feedback["lead id"] = $lead->getId();
  3340.                 }
  3341.                 return $feedback;
  3342.             }
  3343.         }
  3344.         if ($resultout !== null) {
  3345.             if (isset($resultout['validcampaign'])) {
  3346.                 if ($resultout['validcampaign'] == false) {
  3347.                     $feedback = array(
  3348.                         'code' => 404,
  3349.                         'success' => false,
  3350.                         'message' => 'invalid user',
  3351.                         'lead id' => $lead->getId()
  3352.                     );
  3353.                     return $feedback;
  3354.                 }
  3355.             }
  3356.             if (isset($resultout['validcustomer'])) {
  3357.                 if ($resultout['validcustomer'] == false) {
  3358.                     $feedback = array(
  3359.                         'code' => 404,
  3360.                         'success' => false,
  3361.                         'message' => 'invalid user',
  3362.                         'lead id' => $lead->getId()
  3363.                     );
  3364.                     return $feedback;
  3365.                 }
  3366.             }
  3367.             if (isset($resultin['duplicatetracking'])) {
  3368.                 if ($resultin['duplicatetracking'] == true) {
  3369.                     $feedback = array(
  3370.                         'code' => 404,
  3371.                         'success' => false,
  3372.                         'message' => 'duplicate user',
  3373.                         'lead id' => $lead->getId()
  3374.                     );
  3375.                     return $feedback;
  3376.                 }
  3377.             }
  3378.             if (isset($resultin['invalidtracking'])) {
  3379.                 if ($resultin['invalidtracking'] == true) {
  3380.                     $feedback = array(
  3381.                         'code' => 404,
  3382.                         'success' => false,
  3383.                         'message' => 'invalid user',
  3384.                         'lead id' => $lead->getId()
  3385.                     );
  3386.                     return $feedback;
  3387.                 }
  3388.             }
  3389.             /*        if (str_contains($lead->getEmail(), '@test.com') == true){
  3390.                         dd("hola",$resultout,$resultin);
  3391.                     }*/
  3392.         }
  3393.         if ($lead->getProject()->getId() == 65 || $lead->getProject()->getId() == 60){
  3394.             $feedback = array(
  3395.                 'code' => 200,
  3396.                 'success' => true,
  3397.                 'message' => 'valid user',
  3398.                 'lead id' => $lead->getId(),
  3399.                 'price' => $price
  3400.             );
  3401.         }else{
  3402.             $feedback = array(
  3403.                 'code' => 200,
  3404.                 'success' => true,
  3405.                 'message' => 'valid user',
  3406.                 'lead id' => $lead->getId()
  3407.             );
  3408.         }
  3409.         return $feedback;
  3410.     }
  3411.     public function updateproject($project$resultin$revenue$sold,$lead)
  3412.     {
  3413.         $em $this->getDoctrine()->getManager();
  3414.         $project->setRevenue($project->getRevenue() + $revenue);
  3415.         $project->setSold($project->getSold() + $sold);
  3416.         $project->setGross($project->getGross() + 1);
  3417.         if ($resultin['duplicategen'] == true) {
  3418.             $project->setDuplicategen($project->getDuplicategen() + 1);
  3419.             return $project;
  3420.         }
  3421.         if ($resultin['duplicate'] == true) {
  3422.             $project->setDuplicate($project->getDuplicate() + 1);
  3423.             return $project;
  3424.         }
  3425.         if ($resultin['duplicatetracking'] == true) {
  3426.             $project->setDuplicate($project->getDuplicate() + 1);
  3427.             return $project;
  3428.         }
  3429.         if ($resultin['fake'] == true) {
  3430.             $project->setFake($project->getFake() + 1);
  3431.             return $project;
  3432.         }
  3433.         if ($lead->getStatus()->getId() == 2  ){
  3434.             // If the lead is fully validated
  3435.             $project->setValid($project->getValid() + 1);
  3436.             $project->setCapreach($project->getCapreach() + 1);
  3437.             //dd("hola",$project->getValid(),is_numeric($project->getCapping()));
  3438.             if (is_numeric($project->getCapping()) ){
  3439.                 if ($project->getCapping() != 0){
  3440.                     if (($project->getCapping()<=$project->getCapreach())){
  3441.                         $capping $this->getDoctrine()->getRepository(Status::class)->findOneById(12);
  3442.                         $project->setCapreach(0);
  3443.                         $project->setStatus($capping);
  3444.                     }
  3445.                 }
  3446.             }
  3447.             $project->setDailyreach($project->getDailyreach() + 1);
  3448.             $project->setMonthlyreach($project->getMonthlyreach() + 1);
  3449.             //$this->capping($project, 'project');
  3450.         }else{
  3451.             $project->setInvalid($project->getInvalid() + 1);
  3452.         }
  3453.         return $project;
  3454.     }
  3455.     public function capping($entity$type)
  3456.     {
  3457.         $em $this->getDoctrine()->getManager();
  3458.         $active $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(1); // Valid lead status
  3459.         $pause $this->getDoctrine()->getRepository(Status::class)->findOneById(7); // Valid lead status
  3460.         $valid $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // Valid lead status
  3461.         // Calculate valid lead
  3462.         if ($type == 'project') {
  3463.             // Check general capping
  3464.             $leads $this->getDoctrine()->getRepository(Lead::class)->findBy(array
  3465.                 (
  3466.                     'project' => $entity,
  3467.                     'status' => $active
  3468.                 )
  3469.             );
  3470.             if ($entity->getCapping() !== null && count($leads) >= $entity->getCapping()) {
  3471.                 $entity->setStatus($pause);
  3472.                 return $entity;
  3473.             }
  3474.             // Check month capping
  3475.             $fromdate date('Y-m') . '-01 00:00:00';
  3476.             $todate date('Y-m-d') . ' 23:59:59';
  3477.             $repository $this->getDoctrine()->getRepository(Lead::class);
  3478.             $query $repository->createQueryBuilder('c');
  3479.             $query->addSelect('c');
  3480.             $query->leftJoin('App:Project''p''WITH''c.project = p.id');
  3481.             $query->leftJoin('App:Status''s''WITH''c.status = s.id');
  3482.             $query->andWhere('p.id = :project');
  3483.             $query->setParameter('project'$entity->getId());
  3484.             $query->andWhere('s.id = :status');
  3485.             $query->setParameter('status'1);
  3486.             $query->andWhere('c.registrationdate >= :fromdate');
  3487.             $query->andWhere('c.registrationdate <= :todate');
  3488.             $query->setParameter('fromdate'$fromdate);
  3489.             $query->setParameter('todate'$todate);
  3490.             $query $query->getQuery();
  3491.             $leads $query->getResult();
  3492.             if ($entity->getCapping() !== null && count($leads) >= $entity->getMonthlycapping()) {
  3493.                 $entity->setStatus($pause);
  3494.             }
  3495.             return $entity;
  3496.         }elseif($type == "campaign"){
  3497.             // Check general capping
  3498.             $leads $this->getDoctrine()->getRepository(Leadcampaign::class)->findBy(array
  3499.                 (
  3500.                     'campaign' => $entity,
  3501.                     'status' => $active
  3502.                 )
  3503.             );
  3504.             if ($entity->getCapping() != && count($leads) >= $entity->getCapping()) {
  3505.                 return false;
  3506.             }
  3507.             // Check month capping
  3508.             $fromdate date('Y-m') . '-01 00:00:00';
  3509.             $todate date('Y-m-d') . ' 23:59:59';
  3510.             $repository $this->getDoctrine()->getRepository(Leadcampaign::class);
  3511.             $query $repository->createQueryBuilder('c');
  3512.             $query->addSelect('c');
  3513.             $query->leftJoin('App:Campaign''c''WITH''c.campaign = c.id');
  3514.             $query->leftJoin('App:Leadstatus''s''WITH''c.status = s.id');
  3515.             $query->andWhere('c.id = :campaign');
  3516.             $query->setParameter('campaign'$entity->getId());
  3517.             $query->andWhere('s.id = :status');
  3518.             $query->setParameter('status'2);
  3519.             $query->andWhere('c.registrationdate >= :fromdate');
  3520.             $query->andWhere('c.registrationdate <= :todate');
  3521.             $query->setParameter('fromdate'$fromdate);
  3522.             $query->setParameter('todate'$todate);
  3523.             $query $query->getQuery();
  3524.             $leads $query->getResult();
  3525.             if ($entity->getMonthlycapping() != && count($leads) >= $entity->getMonthlycapping()) {
  3526.                 return false;
  3527.             }
  3528.             // Check daily capping
  3529.             $fromdate date('Y-m-d') . ' 00:00:00';
  3530.             $todate date('Y-m-d') . ' 23:59:59';
  3531.             $repository $this->getDoctrine()->getRepository(Leadcampaign::class);
  3532.             $query $repository->createQueryBuilder('c');
  3533.             $query->addSelect('c');
  3534.             $query->leftJoin('App:Campaign''c''WITH''c.campaign = c.id');
  3535.             $query->leftJoin('App:Leadstatus''s''WITH''c.status = s.id');
  3536.             $query->andWhere('c.id = :campaign');
  3537.             $query->setParameter('campaign'$entity->getId());
  3538.             $query->andWhere('s.id = :status');
  3539.             $query->setParameter('status'2);
  3540.             $query->andWhere('c.registrationdate >= :fromdate');
  3541.             $query->andWhere('c.registrationdate <= :todate');
  3542.             $query->setParameter('fromdate'$fromdate);
  3543.             $query->setParameter('todate'$todate);
  3544.             $query $query->getQuery();
  3545.             $leads $query->getResult();
  3546.             if ($entity->getDailycap() != && count($leads) >= $entity->getDailycap()) {
  3547.                 return false;
  3548.             }
  3549.             return true;
  3550.         }
  3551.         return $entity;
  3552.     }
  3553.     public function validator($data$field)
  3554.     {
  3555.         $v $field->getValidator();
  3556.         if ($v['operator'] == 'equal') {
  3557.             if ($v['value'] == $data) {
  3558.                 return true;
  3559.             } else {
  3560.                 return false;
  3561.             }
  3562.         } elseif ($v['operator'] == 'different') {
  3563.             if ($v['value'] !== $data) {
  3564.                 return true;
  3565.             } else {
  3566.                 return false;
  3567.             }
  3568.         } elseif ($v['operator'] == 'contains') {
  3569.             if (strpos($data$v['value']) !== false) {
  3570.                 return true;
  3571.             } else {
  3572.                 return false;
  3573.             }
  3574.         } elseif ($v['operator'] == 'not contains') {
  3575.             if (strpos($data$v['value']) == false) {
  3576.                 return true;
  3577.             } else {
  3578.                 return false;
  3579.             }
  3580.         } else {
  3581.             return true;
  3582.         }
  3583.     }
  3584.     public function hasoffertrk($lead,$data)
  3585.     {
  3586.         $em $this->getDoctrine()->getManager();
  3587.         $clickid $lead->getHs()->getClickid();
  3588.         $tracking $lead->getHs();
  3589.         $conn $em->getConnection();
  3590.         try {
  3591.             if ($lead->getProject()->getRevenueShare()){
  3592.                 if ($lead->getProject()->getTypeRevenueShare()=="roi"){
  3593.                     $hasoffers 'http://trk.loudedig.com/aff_lsr?amount='.$lead->getProject()->getRoi().'&transaction_id='.$clickid;
  3594.                 }else{
  3595.                     if ( $lead->getProject()->getTypeRevenueShare()=="lowest"){
  3596.                         $query 'SELECT 
  3597.                 MIN(revenue) price
  3598.                 FROM leadcampaign lc
  3599.                 WHERE lc.lead_id = :leadid
  3600.                 AND lc.revenue > :revenue
  3601.                 ';
  3602.                     }elseif ($lead->getProject()->getTypeRevenueShare()=="average"){
  3603.                         $query 'SELECT 
  3604.                 AVG (revenue) price
  3605.                 FROM leadcampaign lc
  3606.                 WHERE lc.lead_id = :leadid
  3607.                 AND lc.revenue > :revenue
  3608.                 ';
  3609.                     }elseif ($lead->getProject()->getTypeRevenueShare()=="highest"){
  3610.                         $query 'SELECT 
  3611.                 MAX(revenue) price
  3612.                 FROM leadcampaign lc
  3613.                 WHERE lc.lead_id = :leadid
  3614.                 AND lc.revenue > :revenue
  3615.                 ';
  3616.                     }
  3617.                     $stmt $conn->prepare($query);
  3618.                     $stmt->bindValue('leadid',$lead->getId() , 'string');
  3619.                     $stmt->bindValue('revenue'0'string');
  3620.                     $stmt->execute();
  3621.                     $leadscampaigns $stmt->fetchAll();
  3622.                     if ($lead->getProject()->getTypeRevenueShare() == "roi"){
  3623.                         $price=$lead->getProject()->getRoi();
  3624.                     }else{
  3625.                         $price=$leadscampaigns[0]['price'];
  3626.                     }
  3627.                     $hasoffers 'http://trk.loudedig.com/aff_lsr?amount='.$price.'&transaction_id='.$clickid;
  3628.                 }
  3629.             }elseif(str_contains($lead->getEmail(), '@loudingest.com') == true || str_contains($lead->getEmail(), '@loudingads.com') == true){
  3630.                 $hasoffers 'http://trk.loudedig.com/aff_lsr?amount='.$lead->getProject()->getRoi().'&transaction_id='.$clickid;
  3631.             }
  3632.         } catch(\Exception $e) {
  3633.         }
  3634.         if (str_contains($lead->getEmail(), '@loudingads.com') == true){
  3635.             $hasoffers 'http://trk.loudedig.com/aff_lsr?amount='.$lead->getProject()->getRoi().'&transaction_id='.$clickid;
  3636.         }
  3637.         if (!isset($hasoffers)){
  3638.             if ( $lead->getProject()->getId()==54 || $lead->getProject()->getId() == 56 || $lead->getProject()->getId()==57){
  3639.                 $query 'SELECT 
  3640.                 MIN(revenue) price
  3641.                 FROM leadcampaign lc
  3642.                 WHERE lc.lead_id = :leadid
  3643.                 AND lc.revenue > :revenue
  3644.                 ';
  3645.                 $stmt $conn->prepare($query);
  3646.                 $stmt->bindValue('leadid',$lead->getId() , 'string');
  3647.                 $stmt->bindValue('revenue'0'string');
  3648.                 $stmt->execute();
  3649.                 $leadscampaigns $stmt->fetchAll();
  3650.                 $price $leadscampaigns[0]['price'];
  3651.                 $hasoffers 'http://trk.loudedig.com/aff_lsr?amount='.$leadscampaigns[0]['price'].'&transaction_id='.$clickid;
  3652.             }else{
  3653.                 $hasoffers 'https://loudingads.go2cloud.org/aff_lsr?transaction_id=' $clickid;
  3654.             }
  3655.         }
  3656.         $hasoffers file_get_contents($hasoffers);
  3657.         $tracking->setResponse($hasoffers);
  3658.         $em->persist($tracking);
  3659.         $em->flush();
  3660.         if (strpos($hasoffers'success=false') !== false) {
  3661.             return null;
  3662.         }
  3663.         $cost 'https://loudingads.api.hasoffers.com/Apiv3/json?NetworkToken=NETfLjuz52LTPJ2aOWXOruj7Lo7u7l&Target=Offer&Method=getAffiliatePayment&offer_id='.$data["offer"].'&affiliate_id='.$data["source"];
  3664.         $response file_get_contents($cost);
  3665.         // Decode the response into a PHP associative array
  3666.         $response json_decode($response);
  3667.         if (isset($response->response->data->payout_type)) {
  3668.             if ($response->response->data->payout_type == "cpa_percentage") {
  3669.                 if (isset($price)){
  3670.                     try {
  3671.                         $price $price*$response->response->data->percent_payout/100;
  3672.                         $response->response->data->price=$price;
  3673.                     }catch(\Exception $e){
  3674.                     }
  3675.                 }
  3676.             }
  3677.         }
  3678.         return $response;
  3679.     }
  3680.     public function webservice($ws$fields)
  3681.     {
  3682.         $em $this->getDoctrine()->getManager();
  3683.         $header $ws->getHeader();
  3684.         $url $ws->getUrl();
  3685.         $method $ws->getMethod();
  3686.         $fixed $ws->getFields();
  3687.         $f = array();
  3688.         foreach ($fixed as $key => $value) {
  3689.             $f[$value['field']] = $value['value'];
  3690.         }
  3691.         if (count($f) > 0) {
  3692.             $fields array_merge($fields$f);
  3693.         }
  3694.         $ch curl_init();
  3695.         if ($method == 0) { // GET
  3696.             $url $url '&' http_build_query($fields);
  3697.             curl_setopt($chCURLOPT_URL$url);
  3698.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  3699.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  3700.         } else { // POST
  3701.             if ($ws->getDatatype() == 1) {
  3702.                 $fields json_encode($fields);
  3703.             }
  3704.             curl_setopt($chCURLOPT_URL$url);
  3705.             curl_setopt($chCURLOPT_POST1);
  3706.             curl_setopt($chCURLOPT_POSTFIELDS$fields);
  3707.             curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
  3708.             curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  3709.             if (count($header) > 0) {
  3710.                 foreach ($header as $h) {
  3711.                     $hd[] = $h['value'];
  3712.                 }
  3713.                 curl_setopt($chCURLOPT_HTTPHEADER$hd);
  3714.             }
  3715.         }
  3716.         $response curl_exec($ch);
  3717.         if ($method == 0) {
  3718.             $wscall json_encode(curl_getinfo($ch), JSON_UNESCAPED_SLASHES);
  3719.         } else {
  3720.             if (count($header) == 0) {
  3721.                 $hd null;
  3722.             }
  3723.             $wscall json_encode(
  3724.                 array(
  3725.                     'header' => $hd,
  3726.                     'data' => $fields,
  3727.                     'call' => json_encode(curl_getinfo($ch))
  3728.                 , JSON_UNESCAPED_SLASHES)
  3729.             );
  3730.         }
  3731.         $feedback = array(
  3732.             'response' => $response,
  3733.             'wscall' => $wscall
  3734.         );
  3735.         curl_close($ch);
  3736.         return $feedback;
  3737.     }
  3738.     public function project(Request $request)
  3739.     {
  3740.         $data $request->request->all();
  3741.         if (isset($data['domain'])) {
  3742.             $domain $data['domain'];
  3743.         } else {
  3744.             $domain null;
  3745.         }
  3746.         $em $this->getDoctrine()->getManager();
  3747.         $active $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
  3748.         $project $this->getDoctrine()->getRepository(Project::class)->findOneBy(array(
  3749.                 'domain' => $domain,
  3750.                 'status' => $active
  3751.             )
  3752.         );
  3753.         $headers $this->getDoctrine()->getRepository(Header::class)->findBy(array(
  3754.                 'project' => $project,
  3755.                 'status' => $active
  3756.             )
  3757.         );
  3758.         $h = array();
  3759.         if (count($headers) > 0) {
  3760.             foreach ($headers as $header) {
  3761.                 $h[] = array(
  3762.                     'name' => $header->getName(),
  3763.                     'code' => $header->getCode(),
  3764.                     'version' => $header->getVersion()
  3765.                 );
  3766.             }
  3767.         }
  3768.         if ($project !== null) {
  3769.             $project = array(
  3770.                 'id' => $project->getId(),
  3771.                 'name' => $project->getName(),
  3772.                 'country' => $project->getCountry()->getCode(),
  3773.                 'lang' => $project->getLang()->getCode(),
  3774.                 'header' => $h
  3775.             );
  3776.         } else {
  3777.             $project = array(
  3778.                 'id' => null
  3779.             );
  3780.         }
  3781.         return $this->json($project);
  3782.     }
  3783.     public function content(Request $request)
  3784.     {
  3785.         $data $request->request->all();
  3786.         $active $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
  3787.         if (isset($data['project'])) {
  3788.             $project $this->getDoctrine()->getRepository(Project::class)->findOneById($data['project']);
  3789.             $contact $this->getDoctrine()->getRepository(Projectmail::class)->findOneBy(array(
  3790.                 'project' => $project,
  3791.                 'status' => $active
  3792.             ));
  3793.             $projectdata = array(
  3794.                 'id' => $project->getId(),
  3795.                 'name' => $project->getName(),
  3796.                 'country' => $project->getCountry()->getCode(),
  3797.                 'domain' => $project->getDomain(),
  3798.                 'contact' => $contact->getEmail()
  3799.             );
  3800.         } else {
  3801.             $project null;
  3802.             $projectdata null;
  3803.         }
  3804.         if (isset($data['type'])) {
  3805.             $type $this->getDoctrine()->getRepository(PageType::class)->findOneBy(array(
  3806.                 'name' => $data['type'],
  3807.             ));
  3808.         } else {
  3809.             $type null;
  3810.         }
  3811.         $content $this->getDoctrine()->getRepository(Page::class)->findOneBy(
  3812.             array(
  3813.                 'project' => $project,
  3814.                 'type' => $type,
  3815.                 'status' => $active
  3816.             )
  3817.         );
  3818.         if ($content !== null) {
  3819.             $content = array(
  3820.                 'id' => $content->getId(),
  3821.                 'title' => $content->getName(),
  3822.                 'text' => $content->getText(),
  3823.                 'shortname' => $content->getShortname(),
  3824.                 'project' => $projectdata
  3825.             );
  3826.         } else {
  3827.             $content = array(
  3828.                 'id' => null
  3829.             );
  3830.         }
  3831.         return $this->json($content);
  3832.     }
  3833.     public function session(Request $request)
  3834.     {
  3835.         $data $request->request->all();
  3836.         if (isset($data['source']) && $data['source'] !== '') {
  3837.             $source $data['source'];
  3838.         } else {
  3839.             $source null;
  3840.         }
  3841.         if (isset($data['ip']) && $data['ip'] !== '') {
  3842.             $ip $data['ip'];
  3843.         } else {
  3844.             $ip null;
  3845.         }
  3846.         if (isset($data['sub1']) && $data['sub1'] !== '') {
  3847.             $sub1 $data['sub1'];
  3848.         } else {
  3849.             $sub1 null;
  3850.         }
  3851.         if (isset($data['sub2']) && $data['sub2'] !== '') {
  3852.             $sub2 $data['sub2'];
  3853.         } else {
  3854.             $sub2 null;
  3855.         }
  3856.         if (isset($data['sub3']) && $data['sub3'] !== '') {
  3857.             $sub3 $data['sub3'];
  3858.         } else {
  3859.             $sub3 null;
  3860.         }
  3861.         if (isset($data['sub4']) && $data['sub4'] !== '') {
  3862.             $sub4 $data['sub4'];
  3863.         } else {
  3864.             $sub4 null;
  3865.         }
  3866.         if (isset($data['cid']) && $data['cid'] !== '') {
  3867.             $cid $data['cid'];
  3868.         } else {
  3869.             $cid null;
  3870.         }
  3871.         $em $this->getDoctrine()->getManager();
  3872.         $project $this->getDoctrine()->getRepository(Project::class)->findOneById($data['project']);
  3873.         $session = new Session();
  3874.         $session->setProject($project);
  3875.         $session->setSession($data['session']);
  3876.         $session->setIp($ip);
  3877.         $session->setReferral($data['referral']);
  3878.         $session->setClient($data['client']);
  3879.         $session->setTimestamp(new \Datetime('Europe/Madrid'));
  3880.         $session->setSource($source);
  3881.         $session->setSub1($sub1);
  3882.         $session->setSub2($sub2);
  3883.         $session->setSub3($sub3);
  3884.         $session->setSub4($sub4);
  3885.         $session->setCid($cid);
  3886.         $em->persist($session);
  3887.         $em->flush();
  3888.         $result = array(
  3889.             'id' => $session->getId()
  3890.         );
  3891.         return $this->json($result);
  3892.     }
  3893.     public function projectmail(Request $request)
  3894.     {
  3895.         $data $request->request->all();
  3896.         if (isset($data['project'])) {
  3897.             $project $this->getDoctrine()->getRepository(Project::class)->findOneById($data['project']);
  3898.         } else {
  3899.             $project null;
  3900.         }
  3901.         if (isset($data['type'])) {
  3902.             $type $data['type'];
  3903.         } else {
  3904.             $type null;
  3905.         }
  3906.         $em $this->getDoctrine()->getManager();
  3907.         $active $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
  3908.         $content $this->getDoctrine()->getRepository(Projectmail::class)->findOneBy(
  3909.             array(
  3910.                 'project' => $project,
  3911.                 'type' => $type,
  3912.                 'status' => $active
  3913.             )
  3914.         );
  3915.         if ($content !== null) {
  3916.             $content = array(
  3917.                 'id' => $content->getId(),
  3918.                 'email' => $content->getEmail()
  3919.             );
  3920.         } else {
  3921.             $content = array(
  3922.                 'id' => null
  3923.             );
  3924.         }
  3925.         return $this->json($content);
  3926.     }
  3927.     public function update(Request $request)
  3928.     {
  3929.         $em $this->getDoctrine()->getManager();
  3930.         $data $request->request->all(); // Get all the data in the Request
  3931.         // Get email from Request
  3932.         if (isset($data['email'])) {
  3933.             $email $data['email'];
  3934.         } else {
  3935.             $email null;
  3936.         }
  3937.         // Get project from Request
  3938.         if (isset($data['project'])) {
  3939.             $project $data['project'];
  3940.         } else {
  3941.             $project null;
  3942.         }
  3943.         // Get lead id from Request
  3944.         if (isset($data['uid'])) {
  3945.             $uid $data['uid'];
  3946.         } else {
  3947.             $uid null;
  3948.         }
  3949.         // Result array
  3950.         $resultin = array(
  3951.             'inactive' => false,
  3952.             'duplicategen' => false,
  3953.             'duplicate' => false,
  3954.             'duplicatetracking' => false,
  3955.             'fake' => false,
  3956.             'validproject' => false,
  3957.             'inserted' => false
  3958.         );
  3959.         $resultout = array(
  3960.             'validcampaign' => false,
  3961.             'validcustomer' => false
  3962.         );
  3963.         $active $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
  3964.         // Check project
  3965.         $project $this->getDoctrine()->getRepository(Project::class)->findOneBy(
  3966.             array(
  3967.                 'id' => $project,
  3968.                 'status' => $active
  3969.             )
  3970.         );
  3971.         // If project doesn't exist or is not active
  3972.         if ($project == null) {
  3973.             $resultin['inactive'] = true;
  3974.             $result $this->feedback($resultin$resultout);
  3975.             return $this->json($result);
  3976.         }
  3977.         // Check if email is valid
  3978.         if (!filter_var($emailFILTER_VALIDATE_EMAIL)) {
  3979.             $resultin['invalid'] = true;
  3980.             $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(3);
  3981.             $lead $this->insertlead($data$project$lead_status);
  3982.             $result $this->feedback($resultin$resultout);
  3983.             return $this->json($result);
  3984.         }
  3985.         // Get lead
  3986.         $lead $this->getDoctrine()->getRepository(Lead::class)->findOneById($uid);
  3987.         if ($lead == null) {
  3988.             return $this->json($resultin);
  3989.         }
  3990.         foreach ($data as $key => $value) {
  3991.             // Get field
  3992.             $field $this->getDoctrine()->getRepository(Field::class)->findOneBy(array(
  3993.                     'project' => $project,
  3994.                     'status' => $active,
  3995.                     'name' => $key
  3996.                 )
  3997.             );
  3998.             if ($field !== null) {
  3999.                 // Get leadfield
  4000.                 $leadfield $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(array(
  4001.                         'lead' => $lead,
  4002.                         'field' => $field
  4003.                     )
  4004.                 );
  4005.                 if ($leadfield->getValue() == null || $leadfield->getValue() == '') {
  4006.                     $leadfield->setValue($value);
  4007.                     $em->persist($leadfield);
  4008.                     $em->flush();
  4009.                 }
  4010.             }
  4011.         }
  4012.         $result $this->feedback($resultin$resultout$lead);
  4013.         return $this->json($result);
  4014.     }
  4015.     public function emailcheck($email)
  4016.     {
  4017.         try {
  4018.             if (!filter_var($emailFILTER_VALIDATE_EMAIL)) {
  4019.                 return 2;
  4020.             }
  4021.             $domain explode('@'$email);
  4022.             if (count(dns_get_record($domain[1], DNS_MX)) < 1) {
  4023.                 return 3;
  4024.             }
  4025.         }catch (\Exception $e){
  4026.             return 3;
  4027.         }
  4028.     }
  4029.     public function getstats(Request $request)
  4030.     {
  4031.         if ($request->request->get('fromdate') !== null) {
  4032.             $fromdate $request->request->get('fromdate');
  4033.         }
  4034.         if ($request->request->get('todate') !== null) {
  4035.             $todate $request->request->get('todate');
  4036.         }
  4037.         if ($request->request->get('campaign') !== null) {
  4038.             $campaign $request->request->get('campaign');
  4039.             $campaign $this->getDoctrine()->getRepository(Campaign::class)->findOneById($campaign);
  4040.         }
  4041.         if ($this->getUser()->getCompany()->getId() !== $campaign->getCompany()->getId()){
  4042.             $result = array(
  4043.                 'success' => false,
  4044.                 'message' => 'Permission denied'
  4045.             );
  4046.             return $this->json($result);
  4047.         }
  4048.         $em $this->getDoctrine()->getManager();
  4049.         $active $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
  4050.         $fields $this->getDoctrine()->getRepository(Fieldcampaign::class)->findBy(
  4051.             array(
  4052.                 'campaign' => $campaign,
  4053.                 'status' => $active
  4054.             )
  4055.         );
  4056.         $select null;
  4057.         $i 1;
  4058.         foreach ($fields as $field) {
  4059.             $select .= '(
  4060.                     SELECT lf.value
  4061.                     FROM leadfield lf
  4062.                         LEFT JOIN fieldcampaign_field fcf on fcf.field_id = lf.field_id
  4063.                         LEFT JOIN fieldcampaign fc on fcf.fieldcampaign_id = fc.id
  4064.                         WHERE lf.lead_id = l.id and fc.id = ' $field->getId() . '
  4065.                 ) as ' $field->getName() . ',';
  4066.             $i++;
  4067.         }
  4068.         $query 'SELECT 
  4069.                 l.id,
  4070.                 lc.id as lcid,
  4071.                 l.email,
  4072.                 l.phone,
  4073.                 l.ip,
  4074.                 l.source,
  4075.                 lc.registrationdate as sysregdate,
  4076.                 ' $select '
  4077.                 s.status
  4078.                 FROM leadcampaign lc
  4079.                     LEFT JOIN lead l on lc.lead_id = l.id
  4080.                     LEFT JOIN campaign c on lc.campaign_id = c.id
  4081.                     LEFT JOIN currency y on lc.currency_id = y.id
  4082.                     LEFT JOIN leadstatus s on lc.status_id = s.id
  4083.                 WHERE lc.campaign_id = :campaign
  4084.                 AND lc.registrationdate >= :fromdate
  4085.                 AND lc.registrationdate <= :todate
  4086.                 ORDER BY l.id asc
  4087.                 ';
  4088.         $conn $em->getConnection();
  4089.         $stmt $conn->prepare($query);
  4090.         $stmt->bindValue('campaign'$campaign->getId(), 'string');
  4091.         $stmt->bindValue('fromdate'$fromdate'string');
  4092.         $stmt->bindValue('todate'$todate'string');
  4093.         $stmt->execute();
  4094.         $leads $stmt->fetchAll();
  4095.         //Voltalia Change mehdi source
  4096.         try {
  4097.             if ($campaign->getId() == 315){
  4098.                 foreach ($leads as $lead){
  4099.                     if ($lead["source"] == 1674){
  4100.                         $lead["source"] = "3184";
  4101.                     }
  4102.                 }
  4103.             }
  4104.         } catch (\Exception $e){
  4105.         }
  4106.         return $this->json($leads);
  4107.     }
  4108.     public function getThankYouPage(Request $request)
  4109.     {
  4110.         $data $request->request->all();
  4111.         $project $this->getDoctrine()->getRepository(Project::class)->findOneById($data['project']);
  4112.         $thankyou $this->getDoctrine()->getRepository(ThankYou::class)->findOneBy(
  4113.             ['project' => $data['project'],
  4114.                 'status' => [1]],
  4115.             ['id' => 'DESC']
  4116.         );
  4117.         $campaigns = [];
  4118.         if(count($project->getCampaignThankYou()) == 0) {
  4119.             $thpgs = array();
  4120.                 $thpgs[0]['tytitle'] = $thankyou->getTitle();
  4121.                 $thpgs[0]['tydescription'] = $thankyou->getDescription();
  4122.                 $thpgs[0]['tyid'] = $thankyou->getId();
  4123.             return $this->json($thpgs);
  4124.         }
  4125.         foreach ($project->getCampaignThankYou() as $campaign) {
  4126.             if ($campaign->getStatus()->getId() == 1) {
  4127.                 array_push($campaigns$campaign);
  4128.             }
  4129.         }
  4130.         $thpgs = array();
  4131.         $i 0;
  4132.         if ($campaigns==null){
  4133.             $thpgs[$i]['tytitle'] = $thankyou->getTitle();
  4134.             $thpgs[$i]['tydescription'] = $thankyou->getDescription();
  4135.             $thpgs[$i]['tyid'] = $thankyou->getId();
  4136.         }else{
  4137.             foreach ($campaigns as $thpg) {
  4138.                 if ($thpg != null) {
  4139.                     $thpgs[$i]['title'] = $thpg->getTitle();
  4140.                     $thpgs[$i]['tytitle'] = $thankyou->getTitle();
  4141.                     $thpgs[$i]['subtitle'] = $thpg->getSubtitle();
  4142.                     $thpgs[$i]['url'] = $thpg->getURL();
  4143.                     $thpgs[$i]['image'] = $thpg->getImage();
  4144.                     $thpgs[$i]['description'] = $thpg->getDescription();
  4145.                     $thpgs[$i]['tydescription'] = $thankyou->getDescription();
  4146.                     $thpgs[$i]['tyid'] = $thankyou->getId();
  4147.                     $thpgs[$i]['calltoaction'] = $thpg->getCalltoaction();
  4148.                     $thpgs[$i]['status'] = $thpg->getStatus();
  4149.                 }
  4150.                 $i++;
  4151.             }
  4152.         }
  4153.         return $this->json($thpgs);
  4154.     }
  4155.     public function sendToServer($lead){
  4156.         $servers=$this->getDoctrine()->getRepository(ServerToServer::class)->findBy(array(
  4157.             'project' => $lead->getProject(),
  4158.             'status' => 1
  4159.         ));
  4160.         foreach ($servers as $server) {
  4161.             if ($lead->getSource() == $server->getSource()->getExternalid()) {
  4162.                 $webservice "";
  4163.                 if ($server->getSource()->getStatus()->getId() == 1) {
  4164.                     switch ($server->getCode()) {
  4165.                         case "isolatiefacebook"// Loudingads leadgen ES
  4166.                             $webservice $this->forward('App\Controller\ServerLogServiceController::isolatiefacebook', array('email' => $lead->getEmail()))->getContent();
  4167.                             break;
  4168.                     }
  4169.                     if ($webservice != "") {
  4170.                         $webservice json_decode($webservice);
  4171.                         $log = new ServerToServerLog();
  4172.                         $log->setDate(time());
  4173.                         $log->setResponse($webservice);
  4174.                         $log->setServer($server);
  4175.                         $log->setLead($lead);
  4176.                         $em $this->getDoctrine()->getManager();
  4177.                         $em->persist($log);
  4178.                         $em->flush();
  4179.                     }
  4180.                 }
  4181.             }
  4182.         }
  4183.     }
  4184.     public function validatedoiemail(Request $request){
  4185.         $lead $request->request->get("uuid");
  4186.         $lead=urldecode($lead);
  4187.         if (str_contains($lead," ")){
  4188.             $leadstr_replace(" ","+",$lead);
  4189.         }
  4190.         $decrypt openssl_decrypt(
  4191.             $lead,
  4192.             "aes128",
  4193.             "vLjow7178",
  4194.             0,
  4195.             $iv="7983248923794221"
  4196.         );
  4197.         $log $this->getDoctrine()->getRepository(DoiLogs::class)->findOneBy(
  4198.             array(
  4199.                 'lead' => $decrypt,
  4200.             )
  4201.         );
  4202.         $lead $this->getDoctrine()->getRepository(Lead::class)->findOneBy(
  4203.             array(
  4204.                 'id' => $decrypt,
  4205.             )
  4206.         );
  4207.         /*   if ($lead=="UiuK6yeLgJ7fVm9fscXStw=="){
  4208.                dd("holi",$decrypt." nada", $log);
  4209.            }*/
  4210.         $validate 0;
  4211.         if ($log!=null){
  4212.             if ($log->getConfirmation() != ){
  4213.                 $log->setConfirmationdate(time());
  4214.                 $log->setResponse("true");
  4215.                 $log->setConfirmation(1);
  4216.                 $em $this->getDoctrine()->getManager();
  4217.                 $em->persist($log);
  4218.                 $em->flush();
  4219.                 $validate 1;
  4220.                 //we should send the lead to the doubleoptime campaigns here
  4221.                 $data["offer"] =strval$this->getDoctrine()->getRepository(Hasoffers::class)->findOneById(
  4222.                     array(
  4223.                         'id' => $lead->getHs(),
  4224.                     )
  4225.                 )->getOffer());
  4226. //$input = 'https://www.blablablabla/h4/?offer=2312&source=4321&sub1=23848251207530664&[…]1237&utm_medium=email&utm_campaign=0&utm_content=v4';
  4227. //
  4228. //parse_str(parse_url($input, PHP_URL_QUERY), $results);
  4229. //
  4230. //var_dump($results);
  4231. //Example:
  4232. //$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";
  4233. //parse_str(parse_url($input, PHP_URL_QUERY), $results);
  4234. //
  4235. //var_dump($results["offer"],$results["source"]);
  4236.                 $data["source"]=$lead->getSource();
  4237.                 $project $this->getDoctrine()->getRepository(Lead::class)->findOneBy(
  4238.                     array(
  4239.                         'id' => $decrypt,
  4240.                     )
  4241.                 )->getProject();
  4242.                 $repository $this->getDoctrine()->getRepository(Campaign::class);
  4243.                 $query $repository->createQueryBuilder('c');
  4244.                 $query->addSelect('c');
  4245.                 $query->leftJoin('App:Status''s''WITH''c.status = s.id');
  4246.                 $query->leftJoin('App:LeadVerification''lv''WITH''c.sending = lv.id');
  4247.                 $query->andWhere(':project MEMBER OF c.project');
  4248.                 $query->setParameter('project'$project->getId());
  4249.                 $query->andWhere('s.id = :status');
  4250.                 $query->setParameter('status'1);
  4251.                 $query->andWhere('lv.id = :verification');
  4252.                 $query->setParameter('verification'2);
  4253.                 $query $query->getQuery();
  4254.                 $campaigns $query->getResult();
  4255.                 if (count($campaigns) != 0){
  4256.                     $resultout $this->export($lead$project$campaigns);
  4257.                     $revenue $resultout['revenue'];
  4258.                     $resultin["invaliddomain"] = false;
  4259.                     $resultin["invalidemail"] = false;
  4260.                     $resultin["duplicategen"] = false;
  4261.                     $resultin["duplicate"] = false;
  4262.                     $resultin["duplicatetracking"] = false;
  4263.                     $resultin["validproject"] = true;
  4264.                     $resultin["fake"] = false;
  4265.                     $resultin["roifail"] = false;
  4266.                     $sold $resultout['sold'];
  4267.                     $lead->setRevenue($revenue);
  4268.                     if ($lead->getRevenue() < $project->getRoi()) {
  4269.                         $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(16); // roi fail
  4270.                         $lead->setStatus($lead_status); // roi not reached
  4271.                         $resultin['roifail'] = true;
  4272.                         $em->persist($lead);
  4273.                         $em->flush();
  4274.                         $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold); // End of process
  4275.                         return $result;
  4276.                     } else {
  4277.                         $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // valid lead
  4278.                         $lead->setStatus($lead_status); // roi reached
  4279.                     }
  4280.                     if ($lead->getHs() != null) { // Only if the campaign is tracked in HasOffers
  4281.                         $tracking $this->hasoffertrk($lead$data);
  4282.                         if ($tracking !== null) {
  4283.                             if (isset($tracking->response->data->payout)){
  4284.                                 $cost $tracking->response->data->payout;
  4285.                                 if (isset($tracking->response->data->price)){
  4286.                                     $cost $tracking->response->data->price;
  4287.                                 }
  4288.                                 if ($cost == null) {
  4289.                                     $cost 0;
  4290.                                 }
  4291.                             }else{
  4292.                                 $cost=0;
  4293.                             }
  4294.                             $lead->setCost(floatval($cost));
  4295.                         } else { // If HasOffers reject the lead as duplicate
  4296.                             if ($lead->getStatus()->getId() == || $lead->getStatus()->getId() == ){
  4297.                                 $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(6);
  4298.                                 $lead->setStatus($lead_status); // duplicate lead
  4299.                                 //$resultin['duplicatetracking'] = true;
  4300.                                 $resultin['invalidtracking'] = true;
  4301.                             }
  4302.                         }
  4303.                     } else {
  4304.                         $lead_status $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(1);
  4305.                         $lead->setStatus($lead_status); // active lead
  4306.                     }
  4307.                     $em->persist($lead);
  4308.                     $em->flush();
  4309.                     $result $this->closeprcs($project$resultin$resultout$lead$revenue$sold);
  4310.                     return $this->json(1);
  4311.                 }
  4312.             }else{
  4313.                 $validate=0;
  4314.             }
  4315.         }else{
  4316.             $validate=0;
  4317.         }
  4318.         return $this->json($validate);
  4319.     }
  4320.     public function getUrlRedirection(Request $request){
  4321.         $data $request->request->all();
  4322.         $campaign $this->getDoctrine()->getRepository(Campaign::class)->findOneById(376);
  4323.         $lead $this->getDoctrine()->getRepository(Lead::class)->findOneById($data["leadid"]);
  4324.         $wslog $this->getDoctrine()->getRepository(Wslog::class)->findOneBy(
  4325.             array(
  4326.                 'campaign' => $campaign,
  4327.                 'lead' => $data["leadid"]
  4328.             )
  4329.         );
  4330.         if($wslog !== null && $wslog->getFeedback() !== null) {
  4331.             $feedbackwslog json_decode($wslog->getFeedback());
  4332.             $redirectURL $feedbackwslog->redirect_url;
  4333.         } else {
  4334.             $redirectURL 0;
  4335.         }
  4336.         return $this->json($redirectURL);
  4337.     }
  4338.     public function redirectmeilleaurtaux(Request $request){
  4339.         $data $request->request->all();
  4340.         $feedback json_decode($data["result"]);
  4341.         $campaign $this->getDoctrine()->getRepository(Campaign::class)->findOneById(263);
  4342.         $lead $this->getDoctrine()->getRepository(Lead::class)->findOneById($feedback->leadid);
  4343.         $wslog $this->getDoctrine()->getRepository(Wslog::class)->findOneBy(
  4344.             array(
  4345.                 'campaign' => $campaign,
  4346.                 'lead' => $lead
  4347.             )
  4348.         );
  4349.         if($wslog !== null && $wslog->getFeedback() !== null) {
  4350.             $feedbackwslog json_decode($wslog->getFeedback());
  4351.             $redirectURL $feedbackwslog->RedirectUrl;
  4352.         } else {
  4353.             $redirectURL 0;
  4354.         }
  4355.         return $this->json($redirectURL);
  4356.     }
  4357.     // Antifraud system
  4358.     public function antifraud($lead$data) {
  4359.         // Check project fraud system
  4360.         $em $this->getDoctrine()->getManager();
  4361.         if($lead->getProject()->getAppFraud() !== null) { // Check if there's an antifraud system
  4362.             if(isset($data['antifraudid']) == true) { // Check if data has anifraud id
  4363.                 if($lead->getProject()->getAppFraud() !== null) { // Check if project has antifraud
  4364.                     if($lead->getProject()->getAppFraud()->getId() == 1) { // Opticks antifraud system
  4365.                         // Opticks
  4366.                         $opticks = new AppOpticksController($em); // invoke controller
  4367.                         $fraudcheck $opticks->leadcheck($lead->getProject()->getAppFraud(), $data['antifraudid'], $lead);
  4368.                     }elseif ($lead->getProject()->getAppFraud()->getId() == 4){
  4369.                         //Recaptcha
  4370.                         $recaptcha = new RecaptchaController($em); // invoke controller
  4371.                         $fraudcheck $recaptcha->leadcheck($lead->getProject()->getAppFraud(), $data['tokenrecaptcha'], $lead);
  4372.                     }
  4373.                     return $fraudcheck// Antifraud entity
  4374.                 }
  4375.             }elseif (isset($data['tokenrecaptcha']) == true){
  4376.                 if($lead->getProject()->getAppFraud() !== null) { // Check if project has antifraud
  4377.                     if ($lead->getProject()->getAppFraud()->getId() == 4){
  4378.                         $recaptcha = new RecaptchaController($em); // invoke controller
  4379.                         $fraudcheck $recaptcha->leadcheck($lead->getProject()->getAppFraud(), $data['tokenrecaptcha'], $lead);
  4380.                         return $fraudcheck// Antifraud entity
  4381.                     }
  4382.                 }
  4383.             }
  4384.         }
  4385.         return null;
  4386.     }
  4387.     public function sellping($lead,$project,$campaigns,$test,$ping$apiinboundtraffic){
  4388.         $em $this->getDoctrine()->getManager();
  4389.         $feedback '';
  4390.         $allresultsping = array(); // array with the collection of the results of all customer's ping response
  4391.         $pingresults = array(); // only with the prices to display to the publihers
  4392.         $counter 0;
  4393.         if($project->getCommissions() !== null) {
  4394.             $commission $project->getCommissions();
  4395.         } else {
  4396.             $commission 1;
  4397.         }
  4398.         foreach ($campaigns as $campaign){
  4399.             $this->mergefields($project,$campaign,$lead);
  4400.             $filterresult $this->checkcampaignfilter($lead$campaign);
  4401.             if ($filterresult == true){
  4402.                 $resultoutPing $this->exportInboundPing($ping,$project,$campaign);
  4403.                 if ($resultoutPing['price'] == || $resultoutPing['check'] == 0){ // Ping not accepted
  4404.                     unset($campaigns[$counter]);
  4405.                 } elseif (($project->getMinimumPrice() !== null && $project->getMinimumPrice() !== '0') && $project->getMinimumPrice() > $resultoutPing['price']){ // Ping price below
  4406.                     unset($campaigns[$counter]);
  4407.                 } else {
  4408.                     $pingaccepted = array(
  4409.                         'price' => $resultoutPing['price'],
  4410.                         'campaign' => $campaign->getId(),
  4411.                         'pingid'  => $resultoutPing['pingid']
  4412.                     );
  4413.                     array_push($allresultsping,$pingaccepted);
  4414.                     $pingresults[] = array(
  4415.                         'value' => round(($pingaccepted['price'] * $commission 100),2),
  4416.                         'currency' => $project->getCurrency()->getSymbol()
  4417.                     );
  4418.                     $counter++; // add a counter only if the ping is been accepted
  4419.                 }
  4420.             }
  4421.         }
  4422.         try {
  4423.             usort($allresultsping, function (array $a, array $b) { return $b['price'] <=> $a['price']; });
  4424.         }catch(\Exception $e){
  4425.             $process_success $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(4); // error
  4426.             $publisherprice '0.00';
  4427.             $apiinboundtraffic->setStatus($process_success);
  4428.             $em->persist($apiinboundtraffic);
  4429.             $ping->setStatus($process_success);
  4430.             $em->persist($ping);
  4431.             $resultin['validlead'] = false;
  4432.             $em->flush();
  4433.             return $this->clientfeedback($resultin,$apiinboundtraffic,$ping,$publisherprice,$pingresults);
  4434.         }
  4435.         // Calculate price to
  4436.         try {
  4437.             $price $allresultsping[0]['price'];
  4438.             $publisherprice round(($price $commission 100),2);
  4439.             $process_success $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(6); // success
  4440.             $ping->setPricein($price);
  4441.             $ping->setPriceout($publisherprice);
  4442.             //good ping
  4443.             $resultin['validlead'] = true;
  4444.         }catch (\Exception $e){
  4445.             $publisherprice '0.00';
  4446.             $process_success $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(4); // error
  4447.             $resultin['validlead'] = false;
  4448.         }
  4449.         //$resultin['validping'] = true; // display multiple results
  4450.         $apiinboundtraffic->setStatus($process_success);
  4451.         $em->persist($apiinboundtraffic);
  4452.         $ping->setStatus($process_success);
  4453.         $em->persist($ping);
  4454.         $em->flush();
  4455.         $result $this->clientfeedback($resultin,$apiinboundtraffic,$ping,$publisherprice,$pingresults);
  4456.         return $result;
  4457.     }
  4458.     public function mergefields($project$campaign,$lead){
  4459.         $status $this->getDoctrine()->getRepository(Status::class)->findOneById(1); // active
  4460.         $fieldscampaign $this->getDoctrine()->getRepository(Fieldcampaign::class)->findBy(
  4461.             array(
  4462.                 'status' => $status,
  4463.                 'campaign' => $campaign
  4464.             )
  4465.         );
  4466.         $fields = array();
  4467.         foreach ($fieldscampaign as $fc) {
  4468.             $repository $this->getDoctrine()->getRepository(Field::class);
  4469.             $query $repository->createQueryBuilder('c');
  4470.             $query->addSelect('c');
  4471.             $query->andWhere(':fieldcampaign MEMBER OF c.fieldcampaigns');
  4472.             $query->setParameter('fieldcampaign'$fc->getId());
  4473.             $query->andWhere('c.project = :project');
  4474.             $query->setParameter('project'$project->getId());
  4475.             $query $query->getQuery();
  4476.             $field $query->getResult();
  4477.             $fcvalue $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(
  4478.                 array(
  4479.                     'field' => $field,
  4480.                     'lead' => $lead
  4481.                 )
  4482.             );
  4483.             if ($fcvalue !== null) {
  4484.                 $fields[$fc->getName()] = $fcvalue->getValue();
  4485.             } else {
  4486.                 $fields[$fc->getName()] = null;
  4487.             }
  4488.             $fields["original_lead_id"] = $lead->getId();
  4489.         }
  4490.         return $fields;
  4491.     }
  4492.     public function setTestlead($value) {
  4493.         $this->testlead $value;
  4494.     }
  4495.     public function setTestwebservice($value) {
  4496.         $this->testwebservice $value;
  4497.     }
  4498.     public function setApiInboundTraffic(Request $request){
  4499.         $em $this->getDoctrine()->getManager();
  4500.         // Register inbound call details
  4501.         $entity = new ApiInboundTraffic();
  4502.         $entity->setHeaders($request->headers);
  4503.         $entity->setTimestamp(time());
  4504.         $entity->setData(json_encode($request->request->all()));
  4505.         $entity->setMethod($request->server->all()["REQUEST_METHOD"]);
  4506.         $entity->setEndpoint($request->server->all()["REQUEST_URI"]);
  4507.         $entity->setIp($request->server->all()["REMOTE_ADDR"]);
  4508.         $entity->setUser($this->getUser());
  4509.         $active $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(1); // active process
  4510.         $entity->setStatus($active);
  4511.         $em->persist($entity);
  4512.         $em->flush();
  4513.         return $entity;
  4514.     }
  4515.     public function insertping($data$project$status,$apiinboundtraffic)
  4516.     {
  4517.         $em $this->getDoctrine()->getManager();
  4518.         // Mapping data
  4519.         /*if (isset($data['ip'])) {
  4520.             $ip = $data['ip'];
  4521.         } else {
  4522.             $ip = null;
  4523.         }
  4524.         if (isset($data['source']) && $data['source'] !== '') {
  4525.             $source = $data['source'];
  4526.         } else {
  4527.             $source = null;
  4528.         }
  4529.         if (isset($data['url']) && $data['url'] !== '') {
  4530.             $url = $data['url'];
  4531.         } else {
  4532.             $url = null;
  4533.         }
  4534.         /*if (isset($data['registrationdate']) && $data['registrationdate'] !== '') {
  4535.             $registrationdate = new \Datetime($data['registrationdate']);
  4536.         } else {
  4537.             $registrationdate = new \Datetime();
  4538.             $registrationdate->setTimezone(new \DateTimeZone('Europe/Madrid'));
  4539.         }*/
  4540.         // Create the Ping with basic data
  4541.         $date time();
  4542.         $ping = new Ping();
  4543.         $ping->setProject($project);
  4544.         $ping->setStatus($status);
  4545.         //$ping->setRegistrationdate($registrationdate);
  4546.         $ping->setTimestamp($date);
  4547.         //$ping->setSource($source);
  4548.         //$ping->setIp($ip);
  4549.         //$ping->setUrl($url);
  4550.         $ping->setPingtoken(md5(uniqid('varus',true)));
  4551.         $ping->setApiinboundtraffic($apiinboundtraffic);
  4552.         $em->persist($ping);
  4553.         $em->flush();
  4554.         //$ping->setPingtoken(md5('varus'.$date.''.$ping->getId()));
  4555.         //$em->persist($ping);
  4556.         //$em->flush();
  4557.         //$apiinboundtraffic->setPing($ping);
  4558.         //$em->persist($apiinboundtraffic);
  4559.         //$em->flush();
  4560.         return $ping;
  4561.     }
  4562.     public function exportInboundPing($ping,$project,$campaign){
  4563.         $em $this->getDoctrine()->getManager();
  4564.         $status $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
  4565.         $result = array(
  4566.             'price' => 0,
  4567.             'response' => '',
  4568.             'pingid' => ''
  4569.         );
  4570.         // Get all Fieldcampaign
  4571.         $fieldscampaign $this->getDoctrine()->getRepository(Fieldcampaign::class)->findBy(
  4572.             array(
  4573.                 'status' => $status,
  4574.                 'campaign' => $campaign
  4575.             )
  4576.         );
  4577.         $fields = array();
  4578.         // Get the connected Field for each Fieldcampaign
  4579.         foreach ($fieldscampaign as $fc) {
  4580.             $repository $this->getDoctrine()->getRepository(Field::class);
  4581.             $query $repository->createQueryBuilder('c');
  4582.             $query->addSelect('c');
  4583.             $query->andWhere(':fieldcampaign MEMBER OF c.fieldcampaigns');
  4584.             $query->setParameter('fieldcampaign'$fc->getId());
  4585.             $query->andWhere('c.project = :project');
  4586.             $query->setParameter('project'$project->getId());
  4587.             $query $query->getQuery();
  4588.             $field $query->getResult();
  4589.             // Get Pingfield associated with each Field
  4590.             $fcvalue $this->getDoctrine()->getRepository(Pingfield::class)->findOneBy(
  4591.                 array(
  4592.                     'field' => $field,
  4593.                     'ping' => $ping
  4594.                 )
  4595.             );
  4596.             if ($fcvalue !== null) {
  4597.                 $fields[$fc->getName()] = $fcvalue->getValue();
  4598.             } else {
  4599.                 $fields[$fc->getName()] = null;
  4600.             }
  4601.         }
  4602.         $fields['original_lead_id'] = $ping->getId();
  4603.         $test false;
  4604.         //$webservice = $this->forward('App\Controller\WebservicePingPostController::'.$campaign->getFunction().'ping', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
  4605.         if($campaign->getStatus()->getId() == 9) { // Campaign in test mode
  4606.             $test true;
  4607.         }elseif( $fields["firstname"] == "test" ) { // Campaign in test mode
  4608.             $test true;
  4609.         }else {
  4610.             $test false;
  4611.         }
  4612.         $webservice $this->forward('App\Controller\WebServicePingPostController::ping_'.$campaign->getId(), array('data' => $fields'campaign' => $campaign->getId(), 'test' => $test))->getContent();
  4613.         try {
  4614.             $result['response'] = $webservice;
  4615.             $webservice json_decode($webservice);//price,response,wscall,check
  4616.             // Insert the result of the web service call of a single Campaign
  4617.             $typecall $this->getDoctrine()->getRepository(WslogCallType::class)->findOneById(1); // Ping
  4618.             $result['price'] = $webservice->price;
  4619.             $result['pingid'] = $webservice->pingid;
  4620.             $wslog = new WslogInboundPing();
  4621.             $wslog->setCampaign($campaign);
  4622.             $wslog->setPing($ping);
  4623.             $wslog->setResponse($webservice->check);
  4624.             //$wslog->setType($ws->getMethod());
  4625.             $wslog->setTypecall($typecall);
  4626.             $wslog->setFeedback($webservice->response);
  4627.             //$wslog->setTimestamp(new \Datetime('Europe/Madrid'));
  4628.             $wslog->setTimestamp(time());
  4629.             $wslog->setWscall(json_encode($webservice->wscallJSON_UNESCAPED_SLASHES));
  4630.             $wslog->setClientpingid($webservice->pingid);
  4631.             $wslog->setPrice($webservice->price);
  4632.             $em->persist($wslog);
  4633.             $em->flush();
  4634.             $result["check"] = $webservice->check;
  4635.         }catch (\Exception $e){
  4636.             $feedback = array(
  4637.                 'error' => $e->getMessage(),
  4638.                 'line' => $e->getLine(),
  4639.                 'file' => $e->getFile()
  4640.             );
  4641.             $wslog = new WslogInboundPing();
  4642.             $wslog->setCampaign($campaign);
  4643.             $wslog->setPing($ping);
  4644.             $wslog->setResponse(0);
  4645.             if (isset($webservice)){
  4646.                 if (isset($webservice->response)){
  4647.                     $wslog->setFeedback($webservice->response);
  4648.                 }elseif (isset($webservice)){
  4649.                     $wslog->setFeedback($webservice);
  4650.                 }elseif(isset($result['response'])){
  4651.                     $wslog->setFeedback($result['response']);
  4652.                 }else{
  4653.                     $wslog->setFeedback("no webservice");
  4654.                 }
  4655.             }
  4656.             //$wslog->setType($ws->getMethod());
  4657.             $wslog->setTypecall($typecall);
  4658.             //$wslog->setTimestamp(new \Datetime('Europe/Madrid'));
  4659.             $wslog->setTimestamp(time());
  4660.             $wslog->setWscall(json_encode($feedback), JSON_UNESCAPED_SLASHES);
  4661.             $wslog->setPrice(0);
  4662.             $em->persist($wslog);
  4663.             $em->flush();
  4664.             $result["check"] = 0;
  4665.         }
  4666.         return $result;
  4667.     }
  4668.     public function clientfeedback($resultin,$apiinboundtraffic$enity null$price 0$pingresults null)
  4669.     {
  4670.         $em $this->getDoctrine()->getManager();
  4671.         $feedback '';
  4672.         if (isset($resultin['validlead'])) {
  4673.             if ($resultin['validlead'] == true) {
  4674.                 $feedback = array(
  4675.                     'code' => 200,
  4676.                     'success' => true,
  4677.                     'message' => 'Valid Ping',
  4678.                     'ping' => $enity->getPingtoken(),
  4679.                     //'price' =>($price/100*$ping->getProject()->getCommissions()),
  4680.                     'price' => array(
  4681.                         'value' => $price,
  4682.                         'currency' => $enity->getProject()->getCurrency()->getSymbol()
  4683.                     ),
  4684.                 );
  4685.             }
  4686.         } elseif (isset($resultin['validping'])) {
  4687.             if ($resultin['validping'] == true) {
  4688.                 $feedback = array(
  4689.                     'code' => 200,
  4690.                     'success' => true,
  4691.                     'message' => 'Valid Ping',
  4692.                     'ping' => $enity->getPingtoken(),
  4693.                     //'price' =>($price/100*$ping->getProject()->getCommissions()),
  4694.                     'price' => array(
  4695.                         'value' => $price,
  4696.                         'currency' => $enity->getProject()->getCurrency()->getSymbol()
  4697.                     ),
  4698.                     'customers' => $pingresults
  4699.                 );
  4700.             }
  4701.         } elseif (isset($resultin['validpost'])) {
  4702.             if ($resultin['validpost'] == true) {
  4703.                 $feedback = array(
  4704.                     'code' => 200,
  4705.                     'success' => true,
  4706.                     'message' => 'Valid Post',
  4707.                     'ping' => $enity->getPing()->getPingtoken(),
  4708.                     'post' => $enity->getPostToken(),
  4709.                     //'price' =>($price/100*$ping->getProject()->getCommissions()),
  4710.                     //'currency' => $ping->getProject()->getCurrency()->getSymbol()
  4711.                     'price' => array(
  4712.                         'value' => $price,
  4713.                         'currency' => $enity->getProject()->getCurrency()->getSymbol()
  4714.                     ),
  4715.                 );
  4716.             }
  4717.         }elseif (isset($resultin['leadrejected'])) {
  4718.             if ($resultin['leadrejected'] == true) {
  4719.                 $feedback = array(
  4720.                     'code' => 404,
  4721.                     'success' => false,
  4722.                     'lead' => $enity->getId(),
  4723.                     'message' => 'Post rejected by our buyers',
  4724.                     'price' => array(
  4725.                         'value' => $price,
  4726.                         'currency' => $enity->getProject()->getCurrency()->getSymbol()
  4727.                     ),
  4728.                 );
  4729.             }
  4730.         }elseif (isset($resultin['pingrejected'])) {
  4731.             if ($resultin['pingrejected'] == true) {
  4732.                 $feedback = array(
  4733.                     'code' => 404,
  4734.                     'success' => false,
  4735.                     'ping' => $enity->getPing()->getPingtoken(),
  4736.                     'message' => 'No buyers found'
  4737.                 );
  4738.             }
  4739.         }elseif (isset($resultin['doubleping'])) {
  4740.             if ($resultin['doubleping'] == true) {
  4741.                 $feedback = array(
  4742.                     'code' => 404,
  4743.                     'success' => false,
  4744.                     'ping' => $enity->getPing()->getPingtoken(),
  4745.                     'message' => 'Duplicate pingid'
  4746.                 );
  4747.             }
  4748.         }elseif (isset($resultin['fieldsdoesntmatch'])) {
  4749.             if ($resultin['fieldsdoesntmatch'] == true) {
  4750.                 $feedback = array(
  4751.                     'code' => 404,
  4752.                     'success' => false,
  4753.                     'ping' => $enity->getPing()->getPingtoken(),
  4754.                     'message' => 'Values doesn\'t match with the ping values',
  4755.                     'price' => array(
  4756.                         'value' => $price,
  4757.                         'currency' => $enity->getProject()->getCurrency()->getSymbol()
  4758.                     ),
  4759.                 );
  4760.             }
  4761.         }elseif (isset($resultin['nopingidassociated'])) {
  4762.             if ($resultin['nopingidassociated'] == true) {
  4763.                 $feedback = array(
  4764.                     'code' => 404,
  4765.                     'success' => false,
  4766.                     'ping' => $enity,
  4767.                     //'post' => $ping->getPostToken(),
  4768.                     'message' => 'Wrong ping id'
  4769.                 );
  4770.             }
  4771.         }elseif (isset($resultin['missingpingid'])) {
  4772.             if ($resultin['missingpingid'] == true) {
  4773.                 $feedback = array(
  4774.                     'code' => 404,
  4775.                     'success' => false,
  4776.                     'message' => 'Missing pingid'
  4777.                 );
  4778.             }
  4779.         }elseif (isset($resultin['pingsrejected'])) {
  4780.             if ($resultin['pingsrejected'] == true) {
  4781.                 $feedback = array(
  4782.                     'code' => 404,
  4783.                     'success' => false,
  4784.                     'message' => 'No buyers found',
  4785.                     'ping' => $enity->getPingtoken(),
  4786.                     'price' => $price,
  4787.                     'price' => array(
  4788.                         'value' => $price,
  4789.                         'currency' => $enity->getProject()->getCurrency()->getSymbol()
  4790.                     ),
  4791.                 );
  4792.             }
  4793.         }elseif (isset($resultin['invalidproject'])) {
  4794.             if ($resultin['invalidproject'] == true) {
  4795.                 $feedback = array(
  4796.                     'code' => 404,
  4797.                     'success' => false,
  4798.                     'message' => 'Access denied',
  4799.                     //'lead id' => $lead->getId()
  4800.                 );
  4801.             }
  4802.         }elseif (isset($resultin['notallowedprojectstatus'])) {
  4803.             if ($resultin['notallowedprojectstatus'] == true) {
  4804.                 $feedback = array(
  4805.                     'code' => 404,
  4806.                     'success' => false,
  4807.                     'message' => 'not allowed to send leads to this project',
  4808.                     //'lead id' => $lead->getId()
  4809.                 );
  4810.             }
  4811.         }elseif (isset($resultin['clientnoaccess'])) {
  4812.             if ($resultin['clientnoaccess'] == true) {
  4813.                 $feedback = array(
  4814.                     'code' => 404,
  4815.                     'success' => false,
  4816.                     'message' => 'Access denied',
  4817.                     //'lead id' => $lead->getId()
  4818.                 );
  4819.             }
  4820.         }elseif (isset($resultin['filterprojecterror'])) {
  4821.             if ($resultin['filterprojecterror'] == true) {
  4822.                 $feedback = array(
  4823.                     'code' => 404,
  4824.                     'success' => false,
  4825.                     'message' => 'User out of target',
  4826.                     'ping' => $enity->getPingtoken(),
  4827.                     'price' => array(
  4828.                         'value' => $price,
  4829.                         'currency' => $enity->getProject()->getCurrency()->getSymbol()
  4830.                     ),
  4831.                 );
  4832.             }
  4833.         }elseif (isset($resultin['nobuyer'])) {
  4834.             if ($resultin['nobuyer'] == true) {
  4835.                 $feedback = array(
  4836.                     'code' => 404,
  4837.                     'success' => false,
  4838.                     'message' => 'No buyers found',
  4839.                     'ping' => $enity->getPingtoken(),
  4840.                     //'price' => $price
  4841.                     'price' => array(
  4842.                         'value' => $price,
  4843.                         'currency' => $enity->getProject()->getCurrency()->getSymbol()
  4844.                     ),
  4845.                 );
  4846.             }
  4847.         }
  4848.         $apiinboundtraffic->setResponse(json_encode($feedback));
  4849.         $em->persist($apiinboundtraffic);
  4850.         $em->flush();
  4851.         return $feedback;
  4852.     }
  4853.     public function exportInboundPost($lead,$project,$campaign,$post){
  4854.         $em $this->getDoctrine()->getManager();
  4855.         $status $this->getDoctrine()->getRepository(Status::class)->findOneById(1);
  4856.         // Create empty array for response
  4857.         $result = array(
  4858.             'price' => 0,
  4859.             'check' => 0,
  4860.             'response' => null,
  4861.             'pingid' => null,
  4862.             'wslog' => null
  4863.         );
  4864.         // Get all Fieldcampaign for this Campaign
  4865.         $fieldscampaign $this->getDoctrine()->getRepository(Fieldcampaign::class)->findBy(
  4866.             array(
  4867.                 'status' => $status,
  4868.                 'campaign' => $campaign
  4869.             )
  4870.         );
  4871.         $fields = array();
  4872.         foreach ($fieldscampaign as $fc) {
  4873.             // Get the corresponding Field for each Fieldcampaign
  4874.             $repository $this->getDoctrine()->getRepository(Field::class);
  4875.             $query $repository->createQueryBuilder('c');
  4876.             $query->addSelect('c');
  4877.             $query->andWhere(':fieldcampaign MEMBER OF c.fieldcampaigns');
  4878.             $query->setParameter('fieldcampaign'$fc->getId());
  4879.             $query->andWhere('c.project = :project');
  4880.             $query->setParameter('project'$project->getId());
  4881.             $query $query->getQuery();
  4882.             $field $query->getResult();
  4883.             $fcvalue $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(
  4884.                 array(
  4885.                     'field' => $field,
  4886.                     'lead' => $lead
  4887.                 )
  4888.             );
  4889.             if ($fcvalue !== null) {
  4890.                 $fields[$fc->getName()] = $fcvalue->getValue();
  4891.             } else {
  4892.                 $fields[$fc->getName()] = null;
  4893.             }
  4894.         }
  4895.         $fields['original_lead_id'] = $lead->getId();
  4896.         $buyer $this->getDoctrine()->getRepository(WslogInboundPing::class)->findOneBy(
  4897.             array(
  4898.                 'ping' => $post->getPing(),
  4899.                 'response' => 1,
  4900.                 'campaign' => $campaign
  4901.             ),
  4902.         //1
  4903.         );
  4904.         $fields['pingid'] = $buyer->getClientpingid();
  4905.         if($campaign->getStatus()->getId() == 9) {
  4906.             $test true;
  4907.         }else {
  4908.             $test false;
  4909.         }
  4910.         //$webservice = $this->forward('App\Controller\WebservicePingPostController::'.$campaign->getFunction().'post', array('data' => $fields, 'campaign' => $campaign->getId()))->getContent();
  4911.         $webservice $this->forward('App\Controller\WebServicePingPostController::post_'.$campaign->getId(), array('data' => $fields'campaign' => $campaign->getId(),'test'=> $test))->getContent();
  4912.         $typecall $this->getDoctrine()->getRepository(WslogCallType::class)->findOneById(2);
  4913.         //if(json_last_error() === JSON_ERROR_NONE) {
  4914.         try {
  4915.             $result['response'] = $webservice;
  4916.             $webservice json_decode($webservice); // header, post, ch, response, check, price, leadid
  4917.             $wslog null;
  4918.             $result['price'] = $webservice->price;
  4919.             $result['pingid'] = $fields['pingid'];
  4920.             $result['check'] = $webservice->check;
  4921.             $wslog = new Wslog2();
  4922.             $wslog->setCampaign($campaign);
  4923.             $wslog->setLead($lead);
  4924.             $wslog->setResponse($webservice->check);
  4925.             //$wslog->setType($ws->getMethod());
  4926.             $wslog->setTypecall($typecall);
  4927.             $wslog->setFeedback($webservice->response);
  4928.             //$wslog->setTimestamp(new \Datetime('Europe/Madrid'));
  4929.             $wslog->setTimestamp(time());
  4930.             $wslog->setWscall(json_encode($webservice->wscallJSON_UNESCAPED_SLASHES));
  4931.             $wslog->setPost($post);
  4932.             $em->persist($wslog);
  4933.             $em->flush();
  4934.         } catch (\Exception $e){
  4935.             $feedback = array(
  4936.                 'error' => $e->getMessage(),
  4937.                 'line' => $e->getLine(),
  4938.                 'file' => $e->getFile()
  4939.             );
  4940.             $errormessage $e->getLine() . ' ' $e->getMessage();
  4941.             $result['check'] = 0;
  4942.             $wslog = new Wslog2();
  4943.             $wslog->setCampaign($campaign);
  4944.             $wslog->setLead($lead);
  4945.             $wslog->setResponse(0);
  4946.             //$wslog->setType($ws->getMethod());
  4947.             $wslog->setTypecall($typecall);
  4948.             $wslog->setFeedback($errormessage);
  4949.             //$wslog->setTimestamp(new \Datetime('Europe/Madrid'));
  4950.             $wslog->setTimestamp(time());
  4951.             $wslog->setWscall(json_encode($feedback), JSON_UNESCAPED_SLASHES);
  4952.             $wslog->setPost($post);
  4953.             $em->persist($wslog);
  4954.             $em->flush();
  4955.         }
  4956.         //}
  4957.         $result['wslog'] = $wslog;
  4958.         return $result;
  4959.     }
  4960.     public function insertpost($data,$project,$apiinboundtraffic,$ping) {
  4961.         $em $this->getDoctrine()->getManager();
  4962.         $status $this->getDoctrine()->getRepository(Processtatus::class)->findOneById(1); // active process
  4963.         // Mapping data
  4964.         /*if (isset($data['ip'])) {
  4965.             $ip = $data['ip'];
  4966.         } else {
  4967.             $ip = null;
  4968.         }
  4969.         if (isset($data['source']) && $data['source'] !== '') {
  4970.             $source = $data['source'];
  4971.         } else {
  4972.             $source = null;
  4973.         }
  4974.         if (isset($data['url']) && $data['url'] !== '') {
  4975.             $url = $data['url'];
  4976.         } else {
  4977.             $url = null;
  4978.         }
  4979.         if (isset($data['registrationdate']) && $data['registrationdate'] !== '') {
  4980.             $registrationdate = new \Datetime($data['registrationdate']);
  4981.         } else {
  4982.             $registrationdate = new \Datetime();
  4983.             $registrationdate->setTimezone(new \DateTimeZone('Europe/Madrid'));
  4984.         }
  4985.         if (isset($data['project']) && $data['project'] !== '') {
  4986.             $project = $this->getDoctrine()->getRepository(Project::class)->findOneById($data["project"]);
  4987.         }*/
  4988.         // Create the Ping with basic data
  4989.         $post = new Post();
  4990.         if (isset($project)){
  4991.             $post->setProject($project);
  4992.         }
  4993.         $post->setStatus($status);
  4994.         //$post->setRegistrationdate($registrationdate);
  4995.         $post->setTimestamp(time());
  4996.         //$post->setSource($source);
  4997.         $post->setPing($ping);
  4998.         //$post->setUrl($url);
  4999.         $post->setApiinboundtraffic($apiinboundtraffic);
  5000.         $em->persist($post);
  5001.         $em->flush();
  5002.         $post->setPosttoken(md5('varus'.time().''.$post->getId()));
  5003.         $em->persist($post);
  5004.         $em->flush();
  5005.         //$apiinboundtraffic->setPost($post);
  5006.         //$em->persist($apiinboundtraffic);
  5007.         //$em->flush();
  5008.         return $post;
  5009.     }
  5010.     public function setLeadcampaign($leadcampaign,$status,$lead,$campaign,$price 0,$wslog) {
  5011.         $em $this->getDoctrine()->getManager();
  5012.         if($leadcampaign == null) {
  5013.             $leadcampaign = new Leadcampaign();
  5014.         }
  5015.         $leadcampaign->setLead($lead);
  5016.         $leadcampaign->setCampaign($campaign);
  5017.         $leadcampaign->setCurrency($campaign->getCurrency());
  5018.         $leadcampaign->setRevenue($price);
  5019.         $leadcampaign->setReason('pingpost');
  5020.         $leadcampaign->setWslog2($wslog);
  5021.         $leadcampaign->setStatus($status);
  5022.         $leadcampaign->setTimestamp(time());
  5023.         $em->persist($leadcampaign);
  5024.         $em->flush();
  5025.         return $leadcampaign;
  5026.     }
  5027.     public function sellpost($project,$data,$apiinboundtraffic,$ping,$lead){
  5028.         $allresultspost = array(); // array with the collection of the results of all customer's ping response
  5029.         $postresults = array(); // only with the prices to display to the publihers
  5030.         $counter 0;
  5031.         if($project->getCommissions() !== null) {
  5032.             $commission $project->getCommissions();
  5033.         } else {
  5034.             $commission 0;
  5035.         }
  5036.         $post $this->insertpost($data,$project,$apiinboundtraffic,$ping);
  5037.         $buyers $this->getDoctrine()->getRepository(WslogInboundPing::class)->findBy(
  5038.             array(
  5039.                 'ping' => $post->getPing(),
  5040.                 'response' => 1
  5041.             ),
  5042.             array('price' => 'asc'),
  5043.         //1
  5044.         );
  5045.         $campaignsprice = array();
  5046.         foreach($buyers as $buyer){
  5047.             $campaignprice = array(
  5048.                 "id" => $buyer->getCampaign()->getId(),
  5049.                 "price" => (int)$buyer->getPrice(),
  5050.             );
  5051.             array_push($campaignsprice,$campaignprice);
  5052.         }
  5053.         usort($campaignsprice, function (array $a, array $b) { return $b['price'] <=> $a['price']; });
  5054.         $singlesellcampaign $campaignsprice[0]["id"];
  5055.         $campaigns= array();
  5056.         foreach ($campaignsprice as $campaign){
  5057.             $wsping $this->getDoctrine()->getRepository(WslogInboundPing::class)->findOneBy(
  5058.                 array(
  5059.                     'ping' => $post->getPing(),
  5060.                     'response' => 1,
  5061.                     'campaign' => $campaign
  5062.                 ),
  5063.             );
  5064.             array_push($campaigns,$wsping);
  5065.         }
  5066.         foreach ($campaigns as $buyer){
  5067.             if ($counter<1){
  5068.                 $centinel false ;
  5069.                 if (isset($data['test']) && $data['test'] == 1) {
  5070.                     $centinel true;
  5071.                 } elseif($project->getStatus()->getId() == 9) {
  5072.                     $centinel true;
  5073.                 }
  5074.                 if($buyer->getCampaign()->getStatus()->getId() == || $buyer->getCampaign()->getStatus()->getId() == || $centinel == true) {
  5075.                     $resultoutPost $this->exportInboundPost($lead$project$buyer->getCampaign(),$post);
  5076.                     if ($resultoutPost['check'] === 0){
  5077.                         //unset($buyers[$counter]);
  5078.                     }else{ // Post accepted
  5079.                         // Set Leadcampaign
  5080.                         $leadcampaign = new Leadcampaign();
  5081.                         $validlead $this->getDoctrine()->getRepository(Leadstatus::class)->findOneById(2); // valid
  5082.                         $this->setLeadcampaign(
  5083.                             $leadcampaign// new leadcampaign entity
  5084.                             $validlead// leadstatus = valid
  5085.                             $lead// Lead
  5086.                             $buyer->getCampaign(), // Campaign
  5087.                             $resultoutPost['price'], // price retrieved from the call
  5088.                             $resultoutPost['wslog'// entity Wslog2
  5089.                         );
  5090.                         // Update campaign numbers
  5091.                         $postaccepted = array(
  5092.                             //'price' => floatval($resultoutPost["price"]),
  5093.                             'price' => $resultoutPost['price'],
  5094.                             'campaign' =>  $buyer->getCampaign()->getId(),
  5095.                             'pingid'  => $resultoutPost['pingid']
  5096.                         );
  5097.                         array_push($allresultspost,$postaccepted);
  5098.                         $postresults[] = array(
  5099.                             'value' => round(($postaccepted['price'] * $commission 100),2),
  5100.                             'currency' => $project->getCurrency()->getSymbol()
  5101.                         );
  5102.                         $counter++;
  5103.                     }
  5104.                 }
  5105.             }
  5106.         }
  5107.         return $resultoutPost;
  5108.     }
  5109.     public function pingfield($fields$data$ping)
  5110.     {
  5111.         foreach ($fields as $field) {
  5112.             $fieldname $field->getName();
  5113.             if (isset($data[$fieldname])) {
  5114.                 $this->insertpingfield($ping$field$data[$fieldname]);
  5115.             }
  5116.         }
  5117.         return 1;
  5118.     }
  5119.     public function insertpingfield($ping$field$data)
  5120.     {
  5121.         $em $this->getDoctrine()->getManager();
  5122.         // Insert leadfields
  5123.         $pingfield = new Pingfield();
  5124.         $pingfield->setPing($ping);
  5125.         $pingfield->setField($field);
  5126.         $pingfield->setValue($data);
  5127.         $em->persist($pingfield);
  5128.         $em->flush();
  5129.     }
  5130.     public function inboundcalllog(string $header null, array $data nullobject $entity nullstring $response nullobject $lead null) { // set and update inbound call logs
  5131.         $em $this->getDoctrine()->getManager();
  5132.         try{
  5133.             if($entity == null) { // new call received
  5134.                 $entity = new ApiLeadsLogs();
  5135.                 $entity->setUser($this->getUser()); // user that lanched the call
  5136.                 if(isset($data['project'])) {
  5137.                     $project $this->getDoctrine()->getRepository(Project::class)->findOneById($data["project"]);
  5138.                     $entity->setProject($project); // Insert null if project doesn't exist
  5139.                 }
  5140.                 $entity->setTimestamp(time());
  5141.                 $entity->setHeaders($header);
  5142.                 $entity->setData(json_encode($data));
  5143.             } else {
  5144.                 $entity->setLead($lead);
  5145.                 if (str_contains($response,'"success":true,') ){
  5146.                     $entity->setSuccess(true);
  5147.                 }else{
  5148.                     $entity->setSuccess(false);
  5149.                 }
  5150.                 $entity->setResponse($response);
  5151.             }
  5152.             $em->persist($entity);
  5153.             $em->flush();
  5154.         } catch(\Exception $e) {
  5155.             $entity = new ApiLeadsLogs();
  5156.             $entity->setUser($this->getUser());
  5157.             $entity->setTimestamp(time());
  5158.             $entity->setData("Message: ".$e->getMessage().", File: ".$e->getFile().", Line: ".$e->getLine());
  5159.             $em->persist($entity);
  5160.             $em->flush();
  5161.             return false;
  5162.         }
  5163.         return $entity;
  5164.     }
  5165.     public function listleadchecks ($lead){
  5166.         $em $this->getDoctrine()->getManager();
  5167.         $listlead = new ListLeadChecks();
  5168.         $listlead->setLead($lead);
  5169.         $listlead->setCampaignsconnected($this->campaignsconnected);
  5170.         $listlead->setDuplicateemail($this->duplicateemail);
  5171.         $listlead->setDuplicatelephone($this->duplicatelephone);
  5172.         $listlead->setHoneypot($this->honeypotcheck);
  5173.         $listlead->setInvalidemail($this->invalidemailcheck);
  5174.         $listlead->setBlacklisted($this->blacklistedcheck);
  5175.         $listlead->setMandatoryFields($this->mandatoryfields);
  5176.         $listlead->setFieldrules($this->fieldrules);
  5177.         $em->persist($listlead);
  5178.         $em->flush();
  5179.     }
  5180.     public function campaignsconnected($project){
  5181.         $repository $this->getDoctrine()->getRepository(Campaign::class);
  5182.         $query $repository->createQueryBuilder('c');
  5183.         $query->addSelect('c.id');
  5184.         $query->addSelect('c.name');
  5185.         $query->addSelect('c.priority');
  5186.         $query->addSelect('s.status');
  5187.         $query->addSelect('co.name as company');
  5188.         $query->leftJoin('App:Status''s''WITH''c.status = s.id');
  5189.         $query->leftJoin('App:Company''co''WITH''co.id = c.company');
  5190.         $query->andWhere(':project MEMBER OF c.project');
  5191.         $query->setParameter('project'$project->getId());
  5192.         $query->addOrderBy('c.priority','DESC'); // the higher the better
  5193.         $query->addOrderBy('c.price','DESC'); // the higher the better
  5194.         $query $query->getQuery();
  5195.         $campaigns $query->getResult();
  5196.         $connectedcampaigns = [];
  5197.         foreach ($campaigns as $campaign){
  5198.             $arraycampaign = array(
  5199.                 'id' => $campaign["id"],
  5200.                 'name' => $campaign["name"],
  5201.                 'status' => $campaign["status"],
  5202.                 'priority' => $campaign["priority"],
  5203.                 'company' => $campaign["company"]
  5204.             );
  5205.             array_push($connectedcampaigns,$arraycampaign);
  5206.         }
  5207.         return $connectedcampaigns;
  5208.     }
  5209.     public function customFeedback($code,$success,$message,$lead){
  5210.         $result =  array(
  5211.             'code' => $code,
  5212.             'success' => $success,
  5213.             'message' => $message,
  5214.             'lead id' => $lead
  5215.         );
  5216.         return $result;
  5217.     }
  5218.     public function checkMandarotyFields($lead$fields){
  5219.         $result "";
  5220.         foreach ($fields as $field){
  5221.             if ($field->getMandatory() !== null && $field->getMandatory() !== false){
  5222.                 $fieldvalue $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(array(
  5223.                         'lead' => $lead,
  5224.                         'field' => $field
  5225.                     )
  5226.                 );
  5227.                 if (!isset($fieldvalue)){
  5228.                     if ($result == ""){
  5229.                         $result "Missing fields: ".$field->getName();
  5230.                     }else{
  5231.                         $result .= ", ".$field->getName();
  5232.                     }
  5233.                 }
  5234.             }
  5235.         }
  5236.         return $result;
  5237.     }
  5238.     public function checkFieldsRules($lead$fields){
  5239.         $result "";
  5240.         foreach ($fields as $field){
  5241.             if ($field->getFieldrules() !== null && $field->getFieldrules() !== false && $result == ""){
  5242.                 $fieldvalue $this->getDoctrine()->getRepository(Leadfield::class)->findOneBy(array(
  5243.                         'lead' => $lead,
  5244.                         'field' => $field
  5245.                     )
  5246.                 );
  5247.                 if($field->getFieldrules()->getFieldRulesType()->getId() == 1){//Regular expression
  5248.                     //1 success 0 invalid
  5249.                     $check preg_match($field->getFieldrules()->getValue(),$fieldvalue->getValue());
  5250.                     if ($check == 0){
  5251.                         $result "Inserted value is invalid for field: ".$field->getName();
  5252.                     }
  5253.                 }elseif ($field->getFieldrules()->getFieldRulesType()->getId() == 2){//DateFormat
  5254.                     $isItDate date_create_from_format($field->getFieldrules()->getValue(),$fieldvalue->getValue());
  5255.                     if ($isItDate == false){
  5256.                         $result "Inserted value is invalid for field: ".$field->getName();
  5257.                     }
  5258.                 }elseif ($field->getFieldrules()->getFieldRulesType()->getId() == 3){//Select
  5259.                     $values explode(",",$field->getFieldrules()->getValue());
  5260.                     $check in_array($fieldvalue->getValue(),$values);
  5261.                     //true check success
  5262.                     if ($check == false){
  5263.                         $result "Invalid value for field: ".$field->getName();
  5264.                     }
  5265.                 }
  5266.             }
  5267.         }
  5268.         return $result;
  5269.     }
  5270. }