src/Controller/ApiController.php line 4526

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