src/Controller/ApiController.php line 4503

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