src/Controller/ApiController.php line 4503

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