src/Controller/ApiController.php line 4518

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