src/Controller/ApiController.php line 4503

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