src/Controller/ApiController.php line 4654

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