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