src/Controller/KnowledgeBaseController.php line 56

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\Persistence\ManagerRegistry;
  4. use Symfony\Component\HttpKernel\KernelInterface;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. //use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  11. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  12. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  13. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  14. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  15. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  16. use Ivory\CKEditorBundle\Form\Type\CKEditorType;
  17. use Symfony\Component\Console\Input\ArrayInput;
  18. use Symfony\Bundle\FrameworkBundle\Console\Application;
  19. use Symfony\Component\Validator\Constraints\DateTime;
  20. use App\Entity\Eshop;
  21. use App\Entity\EshopLink;
  22. use App\Entity\Service;
  23. use App\Entity\Contact;
  24. use App\Entity\ContactGroup;
  25. use App\Entity\CustomList;
  26. use App\Entity\CustomListItem;
  27. use App\Entity\Address;
  28. use App\Entity\User;
  29. use App\Entity\UserStory;
  30. use App\Entity\Module;
  31. use App\Entity\Consent;
  32. use App\Entity\PriceLevel;
  33. use App\Entity\Order
  34. use App\Entity\TradeLead;
  35. use Symfony\Contracts\Translation\TranslatorInterface;
  36. class KnowledgeBaseController extends DefaultController
  37. {
  38.     protected KernelInterface $appKernel;
  39.     protected ManagerRegistry $doctrine;
  40.     protected TranslatorInterface $translator;
  41.     public function __construct(KernelInterface $appKernel,
  42.                                 ManagerRegistry $doctrine,
  43.                                 TranslatorInterface $translator)
  44.     {
  45.         $this->appKernel $appKernel;
  46.         $this->doctrine $doctrine;
  47.         $this->translator $translator;
  48.     }
  49.     /**
  50.      * @Route("/knowledgebase", name="knowledgebase")
  51.      */
  52.     public function indexAction(Request $request)
  53.     {
  54.         /* we load session data */
  55.         parent::init($request);
  56.         $session $request->getSession();
  57.         /* we load entity managers */
  58.         $em $this->doctrine->getManager();
  59.         /* we load list of modules for connector service */
  60.         $service $em->getRepository(Service::class)->getService(2);
  61.         /* we get current user */
  62.         if (!empty($session->get('user'))) {
  63.             $currentUserId $session->get('user')->getUserId();
  64.             $user $em->getRepository(User::class)->getUser($currentUserId);
  65.             $userModuleList $user->getModules();
  66.         } else {
  67.             $userModuleList = [];
  68.         }
  69.         /* we render data */
  70.         return $this->render('knowledgebase.html.twig',
  71.             array('headerData' => $this -> getPageHeader($request),
  72.                   'moduleList' => $service->getModules(),
  73.                   'userModuleList' => $userModuleList,
  74.                   'service' => $service,
  75.                 )
  76.         );        
  77.     }
  78.     /**
  79.      * @Route("/knowledgebaseAdmin", name="knowledgebaseAdmin")
  80.      */    
  81.     public function knowledgebaseAdminAction(Request $request)
  82.     {
  83.         /* we load session data */
  84.         parent::init($request);
  85.          
  86.         $session $request->getSession();
  87.         /* we check if user is logged in */
  88.         if(empty($session->get('user'))) {
  89.             return $this->redirectToRoute('login');
  90.         }         
  91.         
  92.         /* we load entity managers */
  93.         $em $this->doctrine->getManager();
  94.         $dem $this->doctrine->getManager('dynamic_em');
  95.         
  96.         /* we get current user */
  97.         $currentUserId $session->get('user')->getUserId();
  98.         $user $em->getRepository(User::class)->getUser($currentUserId);
  99.         
  100.         /* we load service */
  101.         $service $em->getRepository(Service::class)->getService(2);
  102.         //we check if user has UserStory module and get recent form responses
  103.         $module $em->getRepository(Module::class)->getModule(24);
  104.         $isModule $em->getRepository(User::class)->userHasModule($user$module);
  105.         $taskList null;
  106.         if($isModule) {
  107.             $dateStart date("Y-m-d",strtotime('monday this week'));
  108.             $dateEnd date("Y-m-d",strtotime('sunday this week'));
  109.             $taskList $dem->getRepository(UserStory::class)->getUserStoryStartBetweenDatesList($dateStart$dateEnd);
  110.         }
  111.         /* we render data */
  112.         return $this->render('knowledgebaseAdmin.html.twig',
  113.                 array(    'headerData' => $this -> getPageHeader($request),
  114.                         'moduleList' => $service->getModules(),
  115.                         'userModuleList' => $user->getModules(),
  116.                         'user' => $user,
  117.                         'menu' => $this -> adminMenu($request),
  118.                         'taskList' => $taskList,
  119.                         'mainMenu' => $this -> adminMainMenu($request)                    
  120.                 )
  121.                 );
  122.     
  123.     }
  124.     
  125.     /**
  126.      * @Route("/contactnew", name="contactNew")
  127.      */
  128.     public function contactNewAction(Request $request)
  129.     {
  130.         /* we load session data */
  131.         parent::init($request);
  132.     
  133.         $session $request->getSession();
  134.     
  135.         $em $this->doctrine->getManager();
  136.         /* we get current user */
  137.         $currentUserId $session->get('user')->getUserId();
  138.         $user $em->getRepository(User::class)->getUser($currentUserId);
  139.         $contact = new Contact();
  140.     
  141.         /* we build login form */
  142.         $formBuilder $this->createFormBuilder($contact);
  143.     
  144.         $formBuilder->add('firstName'TextType::class, array(
  145.                 'required' => true,
  146.                 'label' => $this->translator->trans('knowledgebase.first_name'),
  147.                 'attr' => array('class' => 'text_form''size' => 22),
  148.                 'label_attr' => array('class' => 'form_field_label'),
  149.         ));
  150.         
  151.         $formBuilder->add('lastName'TextType::class, array(
  152.                 'required' => true,
  153.                 'label' => $this->translator->trans('knowledgebase.last_name'),
  154.                 'attr' => array('class' => 'text_form''size' => 22),
  155.                 'label_attr' => array('class' => 'form_field_label'),
  156.         )); 
  157.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  158.                 'attr' => array('class' => 'butt_big')));
  159.         $form $formBuilder->getForm();
  160.         $form->handleRequest($request);
  161.     
  162.         if ($request->getMethod() == 'POST') {
  163.     
  164.             if ($form->isValid()) {
  165.                 // perform some action, such as save the object to the database
  166.     
  167.                 /* we load users entity manager */
  168.                 $dem $this->doctrine->getManager('dynamic_em');
  169.                 $formData $form->getData();
  170.                 print('<br>qqw saving data');
  171.                 \Doctrine\Common\Util\Debug::dump($formData);
  172.                 $address = new Address();
  173.                 $deliveryAddress = new Address();
  174.                 print('<br>qqw firstName form: '.$formData->getFirstName());
  175.                 print('<br>qqw firstName object: '.$contact->getFirstName());
  176.                 $contact->setFirstName($formData->getFirstName());
  177.                 $contact->setLastName($formData->getLastName());
  178.                 //$contact->setAddress($address);
  179.                 //$contact->setDeliveryAddress($deliveryAddress);
  180.                 /* we persist and save */
  181.                 //$dem->persist($address);
  182.                 //$dem->persist($deliveryAddress);
  183.                 $dem->persist($contact);
  184.                 $dem->flush();
  185.                 $this->addFlash('notice'$this->translator->trans('eshop.contact_created'));
  186.                 return $this->redirectToRoute('contactEdit', array('contactId' => $contact->getContactId()));
  187.     
  188.             }
  189.              
  190.         }
  191.     
  192.         /* we render data */
  193.         return $this->render('contactNew.html.twig',
  194.                 array(    'form' => $formBuilder->getForm()->createView(),
  195.                         'headerData' => $this -> getPageHeader($request),
  196.                         'menu' => $this -> adminMenu($request),
  197.                         'user' => $user,
  198.                         'mainMenu' => $this -> adminMainMenu($request)
  199.                 )
  200.                 );
  201.     
  202.     }
  203.     
  204.     /**
  205.      * @Route("/contacts", name="contacts")
  206.      */
  207.     public function contactsAction(Request $request)
  208.     {
  209.     
  210.         /* we load session data */
  211.         parent::init($request);
  212.         $session $request->getSession();
  213.         /* we check if an user is logged in */
  214.         if(empty($session->get('user'))) {
  215.             return $this->redirectToRoute('login');
  216.         }          
  217.     
  218.         /* we load users entity manager */
  219.         $em $this->doctrine->getManager();
  220.         $dem $this->doctrine->getManager('dynamic_em');
  221.         /* removing contact */
  222.         if(!empty($request->query->get('removeContact'))) { 
  223.             //print('<br>qqw removing Contact 33: '.$request->query->get('removeContact'));   
  224.             try {
  225.                 $isRemovable true;
  226.                 $resultMessage '';
  227.                 $contactId $request->query->get('removeContact');
  228.                 $contact $dem->getRepository(Contact::class)->getContact($contactId);
  229.                 //$contact = $dem->getRepository(Contact::class)
  230.                 //removes contacts consents
  231.                 if (!empty($contact->getConsents())) {
  232.                     foreach ($contact->getConsents() as $consent) {
  233.                         //print('<hr>consent: ');  
  234.                         //\Doctrine\Common\Util\Debug::dump($consent);   
  235.                          $contact->removeConsent($consent);
  236.                          $dem->persist($contact);
  237.                          $dem->flush();
  238.                     }
  239.                 }
  240.                 //check orders
  241.                 $orderList $dem->getRepository(Order::class)->getOrderListByCustomer($contact,'orderId','DESC');
  242.                 if (!empty($orderList)) {
  243.                     foreach ($orderList as $order) {
  244.                         //print('<hr>order: '.$order->getOrderId());  
  245.                         $resultMessage .= $order->getOrderId().', ';
  246.                         $isRemovable false;
  247.                     }
  248.                 } 
  249.                 if ($isRemovable) {
  250.                     $contact $dem->getRepository(Contact::class)->removeContact($request->query->get('removeContact'));
  251.                     $this->addFlash('notice'$this->translator->trans('eshop.contact_removed'));
  252.                 } else {
  253.                     $this->addFlash('error''Contact not removed. There are associated orders: '.$resultMessage);
  254.                 }
  255.                 
  256.             } catch(\Doctrine\DBAL\DBALException $e) {
  257.                 $this->addFlash('error'"This contact has connected services (orders etc.), so it can't be removed.");
  258.             }
  259.             
  260.         }
  261.         $userId $session->get('user')->getUserId();
  262.         $user $em->getRepository(User::class)->getUser($userId);
  263.         $contactList $dem->getRepository(Contact::class)->getContactList();
  264.         $contactGroupList $dem->getRepository(ContactGroup::class)->getContactGroupList();
  265.         /* we render data */
  266.         return $this->render('contacts.html.twig',
  267.                 array(    'headerData' => $this -> getPageHeader($request),
  268.                         'contactList' => $contactList,
  269.                         'contactGroupList' => $contactGroupList,
  270.                         'menu' => $this -> adminMenu($request),
  271.                         'user' => $user,
  272.                         'mainMenu' => $this -> adminMainMenu($request)
  273.                 )
  274.                 );
  275.     
  276.     }    
  277.     /**
  278.      * @Route("/contactedit/{contactId}", name="contactEdit")
  279.      */
  280.     public function contactEditAction(Request $request$contactId)
  281.     {
  282.         /* we load session data */
  283.         parent::init($request);
  284.         $session $request->getSession();
  285.         /* we check if an user is logged in */
  286.         if(empty($session->get('user'))) {
  287.             return $this->redirectToRoute('login');
  288.         }
  289.         /* we load entity managers */
  290.         $em $this->doctrine->getManager();
  291.         $dem $this->doctrine->getManager('dynamic_em');
  292.     
  293.         $userId $session->get('user')->getUserId();
  294.         $user $em->getRepository(User::class)->getUser($userId);
  295.         $contact $dem->getRepository(Contact::class)->getContact($contactId);
  296.         //$contactExists = $em->getRepository(Contact::class)->findOneBy(['contactId' => $contactId]);
  297.            //->findOneBy(array('order_id' => $orderId));
  298.         //print('<hr>qqw x contact id 1: '.$contactId.': ');
  299.         //\Doctrine\Common\Util\Debug::dump($contact);
  300.          //print('<hr>qqw x contact id 2: '.$contactId.': ');
  301.          //\Doctrine\Common\Util\Debug::dump($contactExists);
  302.         /* we get collection of contact groups */
  303.         $contactGroupList $dem->getRepository(ContactGroup::class)->getContactGroupList();
  304.         /* we get collection of consents */
  305.         $consents $dem->getRepository(Consent::class)->getConsentList();
  306.         /* we build edit form */ 
  307.         $formBuilder $this->createFormBuilder($contact);
  308.     
  309.         $formBuilder->add('firstName'TextType::class, array(
  310.                 'required' => false,
  311.                 'label' => $this->translator->trans('knowledgebase.first_name'),
  312.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getFirstName()),
  313.                 'label_attr' => array('class' => 'form_field_label')
  314.         ));
  315.         
  316.         $formBuilder->add('middleName'TextType::class, array(
  317.                 'required' => false,
  318.                 'label' => $this->translator->trans('knowledgebase.middle_name'),
  319.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getMiddleName()),
  320.                 'label_attr' => array('class' => 'form_field_label')
  321.         ));        
  322.         
  323.         $formBuilder->add('lastName'TextType::class, array(
  324.                 'required' => false,
  325.                 'label' => $this->translator->trans('knowledgebase.last_name'),
  326.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getLastName()),
  327.                 'label_attr' => array('class' => 'form_field_label')
  328.         ));        
  329.         $formBuilder->add('companyName'TextType::class, array(
  330.                 'required' => false,
  331.                 'label' => $this->translator->trans('knowledgebase.company_name'),
  332.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getCompanyName()),
  333.                 'label_attr' => array('class' => 'form_field_label')
  334.         ));         
  335.         $formBuilder->add('email'TextType::class, array(
  336.                 'required' => false,
  337.                 'label' => $this->translator->trans('knowledgebase.email'),
  338.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getEmail()),
  339.                 'label_attr' => array('class' => 'form_field_label')
  340.         ));           
  341.         $formBuilder->add('email2'TextType::class, array(
  342.                 'required' => false,
  343.                 'label' => $this->translator->trans('knowledgebase.email').' 2',
  344.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getEmail2()),
  345.                 'label_attr' => array('class' => 'form_field_label')
  346.         ));     
  347.         $formBuilder->add('email3'TextType::class, array(
  348.                 'required' => false,
  349.                 'label' => $this->translator->trans('knowledgebase.email').' 3',
  350.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getEmail3()),
  351.                 'label_attr' => array('class' => 'form_field_label')
  352.         ));     
  353.         $formBuilder->add('phone'TextType::class, array(
  354.                 'required' => false,
  355.                 'label' => $this->translator->trans('knowledgebase.phone'),
  356.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getPhone()),
  357.                 'label_attr' => array('class' => 'form_field_label')
  358.         ));   
  359.         $formBuilder->add('phone2'TextType::class, array(
  360.                 'required' => false,
  361.                 'label' => $this->translator->trans('knowledgebase.phone').' 2',
  362.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getPhone2()),
  363.                 'label_attr' => array('class' => 'form_field_label')
  364.         ));  
  365.         $formBuilder->add('phone3'TextType::class, array(
  366.                 'required' => false,
  367.                 'label' => $this->translator->trans('knowledgebase.phone').' 3',
  368.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getPhone3()),
  369.                 'label_attr' => array('class' => 'form_field_label')
  370.         ));    
  371.         /* we set addresses */
  372.         if(empty($contact->getAddress())) {
  373.             $address = new Address;
  374.             $contact->setAddress($address);
  375.         }
  376.         $formBuilder->add('addressStreet'TextType::class, array(
  377.                 'required' => false,
  378.                 'label' => $this->translator->trans('address.street'),
  379.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getAddress()->getStreet()),
  380.                 'label_attr' => array('class' => 'form_field_label_top'),
  381.                 'mapped' => false
  382.         ));
  383.         $formBuilder->add('addressStreetNumber'TextType::class, array(
  384.                 'required' => false,
  385.                 'label' => $this->translator->trans('address.street_number'),
  386.                 'attr' => array('class' => 'text_form''size' => 10'value' => $contact->getAddress()->getStreetNumber()),
  387.                 'label_attr' => array('class' => 'form_field_label'),
  388.                 'mapped' => false
  389.         ));   
  390.         $formBuilder->add('addressZipCode'TextType::class, array(
  391.                 'required' => false,
  392.                 'label' => $this->translator->trans('address.zip_code'),
  393.                 'attr' => array('class' => 'text_form''size' => 10'value' => $contact->getAddress()->getZipCode()),
  394.                 'label_attr' => array('class' => 'form_field_label'),
  395.                 'mapped' => false
  396.         ));          
  397.         $formBuilder->add('addressCity'TextType::class, array(
  398.                 'required' => false,
  399.                 'label' => $this->translator->trans('address.city'),
  400.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getAddress()->getCity()),
  401.                 'label_attr' => array('class' => 'form_field_label'),
  402.                 'mapped' => false
  403.         ));                      
  404.         $formBuilder->add('addressCountry'TextType::class, array(
  405.                 'required' => false,
  406.                 'label' => $this->translator->trans('address.country'),
  407.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getAddress()->getCountry()),
  408.                 'label_attr' => array('class' => 'form_field_label_bottom'),
  409.                 'mapped' => false
  410.         ));                 
  411.         
  412.         /* we set delivery address */
  413.         if(empty($contact->getDeliveryAddress())) {
  414.             $deliveryAddress = new Address;
  415.             $contact->setDeliveryAddress($deliveryAddress);
  416.         }
  417.         $formBuilder->add('deliveryAddressStreet'TextType::class, array(
  418.                 'required' => false,
  419.                 'label' => $this->translator->trans('address.street_delivery'),
  420.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getDeliveryAddress()->getStreet()),
  421.                 'label_attr' => array('class' => 'form_field_label'),
  422.                 'mapped' => false
  423.         ));
  424.         $formBuilder->add('deliveryAddressStreetNumber'TextType::class, array(
  425.                 'required' => false,
  426.                 'label' => $this->translator->trans('address.street_number_delivery'),
  427.                 'attr' => array('class' => 'text_form''size' => 10'value' => $contact->getDeliveryAddress()->getStreetNumber()),
  428.                 'label_attr' => array('class' => 'form_field_label'),
  429.                 'mapped' => false
  430.         ));   
  431.         $formBuilder->add('deliveryAddressZipCode'TextType::class, array(
  432.                 'required' => false,
  433.                 'label' => $this->translator->trans('address.zip_code_delivery'),
  434.                 'attr' => array('class' => 'text_form''size' => 10'value' => $contact->getDeliveryAddress()->getZipCode()),
  435.                 'label_attr' => array('class' => 'form_field_label'),
  436.                 'mapped' => false
  437.         ));          
  438.         $formBuilder->add('deliveryAddressCity'TextType::class, array(
  439.                 'required' => false,
  440.                 'label' => $this->translator->trans('address.city_delivery'),
  441.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getDeliveryAddress()->getCity()),
  442.                 'label_attr' => array('class' => 'form_field_label'),
  443.                 'mapped' => false
  444.         ));                      
  445.         $formBuilder->add('deliveryAddressCountry'TextType::class, array(
  446.                 'required' => false,
  447.                 'label' => $this->translator->trans('address.country_delivery'),
  448.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getDeliveryAddress()->getCountry()),
  449.                 'label_attr' => array('class' => 'form_field_label_bottom'),
  450.                 'mapped' => false
  451.         ));         
  452.         /*  
  453.         $formBuilder->add('address', TextType::class, array(
  454.                 'required' => false,
  455.                 'label' => $this->translator->trans('user.address').' 1',
  456.                 'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getAddress1()),
  457.                 'label_attr' => array('class' => 'form_field_label')
  458.         ));   
  459.         $formBuilder->add('address2', TextType::class, array(
  460.                 'required' => false,
  461.                 'label' => $this->translator->trans('user.address').' 2',
  462.                 'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getAddress2()),
  463.                 'label_attr' => array('class' => 'form_field_label')
  464.         )); 
  465.         $formBuilder->add('invoiceAddress', TextType::class, array(
  466.                 'required' => false,
  467.                 'label' => $this->translator->trans('module.invoice_address').' 1',
  468.                 'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getInvoiceAddress1()),
  469.                 'label_attr' => array('class' => 'form_field_label')
  470.         ));   
  471.         $formBuilder->add('invoiceAddress2', TextType::class, array(
  472.                 'required' => false,
  473.                 'label' => $this->translator->trans('module.invoice_address').' 2',
  474.                 'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $contact->getInvoiceAddress2()),
  475.                 'label_attr' => array('class' => 'form_field_label')
  476.         )); 
  477.         */  
  478.         $formBuilder->add('businessId'TextType::class, array(
  479.                 'required' => false,
  480.                 'label' => $this->translator->trans('user.business_number'),
  481.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getBusinessId()),
  482.                 'label_attr' => array('class' => 'form_field_label')
  483.         ));   
  484.         $formBuilder->add('DICId'TextType::class, array(
  485.                 'required' => false,
  486.                 'label' => $this->translator->trans('user.DIC_number'),
  487.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getDICId()),
  488.                 'label_attr' => array('class' => 'form_field_label')
  489.         ));    
  490.         $formBuilder->add('ERPKey'TextType::class, array(
  491.                 'required' => false,
  492.                 'label' => $this->translator->trans('system.erp_key'),
  493.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getERPKey()),
  494.                 'label_attr' => array('class' => 'form_field_label')
  495.         ));        
  496.         $formBuilder->add('notes'TextareaType::class, array(
  497.                 'required' => false,
  498.                 'label' => $this->translator->trans('system.notes'),
  499.                 'attr' => array('class' => 'textarea_form''cols' => 55'rows' => 4'value' => $contact->getNotes()),
  500.                 'label_attr' => array('class' => 'form_textarea_label'),
  501.                 'data' => $contact->getNotes(),
  502.         ));                
  503.         $formBuilder->add('contactUserName'TextType::class, array(
  504.                 'required' => false,
  505.                 'label' => $this->translator->trans('knowledgebase.user_name'),
  506.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getContactUserName()),
  507.                 'label_attr' => array('class' => 'form_field_label')
  508.         ));    
  509.         
  510.         $formBuilder->add('contactUserPassword'TextType::class, array(
  511.                 'required' => false,
  512.                 'label' => $this->translator->trans('knowledgebase.password'),
  513.                 'attr' => array('class' => 'text_form''size' => 35'value' => $contact->getContactUserPassword()),
  514.                 'label_attr' => array('class' => 'form_field_label')
  515.         ));   
  516.         /* we add all contact groups */
  517.         $contactGroups = array();
  518.         foreach($contactGroupList as $contactGroup)
  519.         {
  520.             $contactGroups[$contactGroup->getContactGroupName()] = $contactGroup->getContactGroupId();
  521.         }
  522. //        print('<br>All ContactGroups: ');
  523. //        print_r($contactGroups);
  524.         $selectedContactGroups = array();
  525. //        print('<br>------------------- ContactGroups 0: ');
  526. //        \Doctrine\Common\Util\Debug::dump($contact->getContactGroups());
  527.         if (!empty($contact->getContactGroups())) {
  528.             foreach($contact->getContactGroups() as $contactGroup) {
  529.               if(!empty($contactGroup)) {
  530.                 $selectedContactGroups[] = $contactGroup->getContactGroupId();
  531.               }
  532.             }
  533.         }
  534. //        print('<br>ContactGroups: ');
  535. //        \Doctrine\Common\Util\Debug::dump($contact->getContactGroups());
  536.         //print_r($contact->getContactGroups());
  537.         $formBuilder->add('contactGroups'ChoiceType::class, array(
  538.                 'choices' => $contactGroups,
  539.                 'required' => false,
  540.                 'mapped' => false,
  541.                 'multiple' => true,
  542.                 'expanded' => true,
  543.                 'label_attr' => array('class' => 'form_field_label'),
  544.                 'attr' => array('class' => 'form_field_text'),
  545.                 'data' => $selectedContactGroups
  546.         ));  
  547.         /* we add all consents */
  548.         $consentList = array();
  549.         foreach($consents as $consent)
  550.         {
  551.             $consent->setLocale($session->get('lang')->getLangKey());
  552.             $dem->refresh($consent);  
  553.             $consentList[$consent->getConsentName()] = $consent->getConsentId();
  554.         }
  555. //        print('<br>------------------- all consents: ');
  556. //        \Doctrine\Common\Util\Debug::dump($consentList);
  557.         $selectedConsents = array();
  558.         if (!empty($contact->getConsents())) {
  559.             foreach ($contact->getConsents() as $consent) {
  560.                 if (!empty($consent)) {
  561.                     $selectedConsents[] = $consent->getConsentId();
  562.                 }
  563.             }
  564.         }
  565.         $formBuilder->add('consents'ChoiceType::class, array(
  566.                 'choices' => $consentList,
  567.                 'required' => false,
  568.                 'mapped' => false,
  569.                 'multiple' => true,
  570.                 'expanded' => true,
  571.                 'label_attr' => array('class' => 'form_field_label'),
  572.                 'attr' => array('class' => 'form_field_text'),
  573.                 'data' => $selectedConsents
  574.         ));   
  575.         //isModule Price Levels
  576.         $module $em->getRepository(Module::class)->getModule(22);
  577.         $isPriceLevelModule $em->getRepository(User::class)->userHasModule($user$module);
  578.         $consentList null;
  579.         if($isPriceLevelModule) {
  580.             //print('<br>qqw is module Price Levels');
  581.             $priceLevels $dem->getRepository(PriceLevel::class)->getPriceLevelList();
  582.             /* we add all price levels */
  583.             $priceLevelList = array();
  584.             foreach($priceLevels as $priceLevel)
  585.             {
  586.                 $priceLevel->setLocale($session->get('lang')->getLangKey());
  587.                 $dem->refresh($priceLevel); 
  588.                 
  589.                 $priceLevelList[$priceLevel->getPriceLevelName()] = $priceLevel->getPriceLevelId();
  590.             }
  591.             $selectedPriceLevels = array();
  592.             $selectedPriceLevel 1;
  593.             if(!empty($contact->getPriceLevel())) {
  594. //                print('<br>contactPriceLevel: ');
  595. //                \Doctrine\Common\Util\Debug::dump($contact->getPriceLevel());
  596.                 //print_r($contact->getPriceLevel());
  597.               //$selectedPriceLevels[] = $contact->getPriceLevel()->getPriceLevelId();
  598.               $selectedPriceLevel $contact->getPriceLevel()->getPriceLevelId();
  599.             }
  600.             $formBuilder->add('priceLevel'ChoiceType::class, array(
  601.                     'choices' => $priceLevelList,
  602.                     'required' => false,
  603.                     'mapped' => false,
  604.                     'multiple' => false,
  605.                     'expanded' => true,
  606.                     'label_attr' => array('class' => 'form_field_label'),
  607.                     'attr' => array('class' => 'form_field_text'),
  608.                     'data' => $selectedPriceLevel
  609.             ));              
  610.         }               
  611.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  612.                 'attr' => array('class' => 'butt_big')));
  613.     
  614.         $form $formBuilder->getForm();
  615.         $form->handleRequest($request);
  616.     
  617.         if ($request->getMethod() == 'POST') {
  618.             if ($form->isValid()) {
  619.                 // perform some action, such as save the object to the database
  620.                 //print('<br>qqw post form 2: ');
  621.                 $formData $form->getData();
  622.     
  623.                 /* we load data from form into contact object */
  624.                 $contact->setFirstName($formData->getFirstName());
  625.                 $contact->setMiddleName($formData->getMiddleName());
  626.                 $contact->setLastName($formData->getLastName());
  627.                 $contact->setCompanyName($formData->getCompanyName());
  628.                 $contact->setEmail($formData->getEmail());
  629.                 $contact->setEmail2($formData->getEmail2());
  630.                 $contact->setEmail3($formData->getEmail3());
  631.                 $contact->setPhone($formData->getPhone());
  632.                 $contact->setPhone2($formData->getPhone2());
  633.                 $contact->setPhone3($formData->getPhone3());
  634.                 $address $contact->getAddress();
  635.                 $address->setStreet($form['addressStreet']->getData());
  636.                 $address->setStreetNumber($form['addressStreetNumber']->getData());
  637.                 $address->setCity($form['addressCity']->getData());
  638.                 $address->setZipCode($form['addressZipCode']->getData());
  639.                 $address->setCountry($form['addressCountry']->getData());
  640.                 //$contact->setAddress($address);
  641.                 $deliveryAddress $contact->getDeliveryAddress();
  642.                 $deliveryAddress->setStreet($form['deliveryAddressStreet']->getData());
  643.                 $deliveryAddress->setStreetNumber($form['deliveryAddressStreetNumber']->getData());
  644.                 $deliveryAddress->setCity($form['deliveryAddressCity']->getData());
  645.                 $deliveryAddress->setZipCode($form['deliveryAddressZipCode']->getData());
  646.                 $deliveryAddress->setCountry($form['deliveryAddressCountry']->getData());
  647.                 //$contact->setDeliveryAddress($deliveryAddress);
  648.                 $contact->setBusinessId($formData->getBusinessId());
  649.                 $contact->setDICId($formData->getDICId());
  650.                 $contact->setNotes($formData->getNotes());
  651.                 $contact->setContactUserName($formData->getContactUserName());
  652.                 // if the password is md5 hash already we do not hash
  653.                 $cuPsw $formData->getContactUserPassword();
  654.                 if(strlen($cuPsw) == 32 && ctype_xdigit($cuPsw)) {
  655.                     $password $cuPsw;
  656.                 } else {
  657.                     $password md5($cuPsw);
  658.                 }
  659.                 $contact->setContactUserPassword($password);
  660.                 // we remove old contact groups
  661.                 if(!empty($contact->getContactGroups())) {
  662.                     foreach ($contact->getContactGroups() as $group) {
  663.                         print('<br>Group: ');
  664.                         $contact->removeContactGroup($group);
  665.                         //$dem->refresh($product);
  666.                         //$dem->persist($cat);
  667.                     }
  668.                 }
  669.                 // we save contact groups
  670.                 $formContactGroups $form['contactGroups']->getData();
  671.                 if(is_array($formContactGroups)) {
  672.                     foreach($formContactGroups as $contactGroupId) {
  673.                         //print('');
  674.                         $group $dem->getRepository(ContactGroup::class)->getContactGroup($contactGroupId);
  675.                         $contact->addContactGroup($group);
  676.                     }
  677.                 }
  678.                 // we save selected price level
  679.                 if($isPriceLevelModule && !empty($form['priceLevel']->getData())) {
  680.                     print('<br>PLId : '.$form['priceLevel']->getData());
  681.                     $priceLevel $dem->getRepository(PriceLevel::class)->getPriceLevel($form['priceLevel']->getData());
  682.                     $contact->setPriceLevel($priceLevel);
  683.                     //print('<br>QQW selected price level: ');
  684.                     //\Doctrine\Common\Util\Debug::dump($priceLevel);
  685.                 }
  686.                 // we remove old consents
  687.                 if(!empty($contact->getConsents())) {
  688.                     foreach ($contact->getConsents() as $consent) {
  689.                         print('<br>Consent: ');
  690.                         $contact->removeConsent($consent);
  691.                     }
  692.                 }
  693.                 // we save consents
  694.                 $formConsents $form['consents']->getData();
  695.                 if(is_array($formConsents)) {
  696.                     foreach($formConsents as $consentId) {
  697.                         $consent $dem->getRepository(Consent::class)->getConsent($consentId);
  698.                         $contact->addConsent($consent);
  699.                     }
  700.                 }
  701.                 /* we persist and save */
  702.                 $em->persist($contact);
  703.                 $dem->flush();
  704.                 $this->addFlash('notice'$this->translator->trans('eshop.contact_updated'));
  705.                 return $this->redirectToRoute('contactEdit', array('contactId' => $contact->getContactId()));
  706.     
  707.             }
  708.     
  709.         }
  710.     
  711.         /* we render data */
  712.         return $this->render('contactEdit.html.twig',
  713.                 array(  'headerData' => $this -> getPageHeader($request),
  714.                         'form' => $formBuilder->getForm()->createView(),
  715.                         'user' => $user,
  716.                         'contact' => $contact,
  717.                         'menu' => $this -> adminMenu($request),
  718.                         'mainMenu' => $this -> adminMainMenu($request)
  719.                 )
  720.                 );
  721.     
  722.     }   
  723.          /**
  724.      * @Route("/contactGroupNew", name="contactGroupNew")
  725.      */
  726.     public function contactGroupNewAction(Request $request)
  727.     {
  728.         /* we load session data */
  729.         parent::init($request);
  730.          
  731.         $session $request->getSession();
  732.         $em $this->doctrine->getManager();
  733.         $userId $session->get('user')->getUserId();
  734.         $user $em->getRepository(User::class)->getUser($userId);
  735.         $contactGroup = new ContactGroup();
  736.         /* we build login form */
  737.         $formBuilder $this->createFormBuilder($contactGroup);
  738.         
  739.         $formBuilder->add('contactGroupName'TextType::class, array(
  740.                 'required' => true,
  741.                 'label' => $this->translator->trans('knowledgebase.contact_group_name'),
  742.                 'attr' => array('class' => 'text_form''size' => 22),
  743.                 'label_attr' => array('class' => 'form_field_label'),
  744.         ));     
  745.     
  746.         //form.button.save
  747.         
  748.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  749.                 'attr' => array('class' => 'butt_big')));
  750.         
  751.         $form $formBuilder->getForm();        
  752.         $form->handleRequest($request);
  753.         
  754.         if ($request->getMethod() == 'POST') {
  755.             if ($form->isValid()) {
  756.                 // perform some action, such as save the object to the database
  757.         
  758.                 /* we load users entity manager */
  759.                 $dem $this->doctrine->getManager('dynamic_em');
  760.                 $formData $form->getData();
  761.                 $contactGroup = new ContactGroup;
  762.                 $contactGroup->setContactGroupName($formData->getContactGroupName());
  763.                 
  764.                 /* we persist and save */
  765.                 $dem->persist($contactGroup);
  766.                 $dem->flush();
  767.                 
  768.                 $this->addFlash('notice''New contact group was created.');
  769.                 
  770.                 return $this->redirectToRoute('contactGroupEdit', array('contactGroupId' => $contactGroup->getContactGroupId()));
  771.         
  772.             }
  773.         
  774.         }
  775.     
  776.         /* we render data */
  777.         return $this->render('contactGroupNew.html.twig',
  778.                 array(  'form' => $formBuilder->getForm()->createView(),
  779.                         'headerData' => $this -> getPageHeader($request),
  780.                         'menu' => $this -> adminMenu($request),
  781.                         'user' => $user,
  782.                         'mainMenu' => $this -> adminMainMenu($request)
  783.                 )
  784.                 );
  785.     
  786.     }  
  787.     /**
  788.      * @Route("/contactGroupEdit/{contactGroupId}", name="contactGroupEdit")
  789.      */
  790.     public function contactGroupEditAction(Request $request$contactGroupId)
  791.     {
  792.         /* we load session data */
  793.         parent::init($request);
  794.         $session $request->getSession();
  795.         
  796.         /* we load entity managers */
  797.         $em $this->doctrine->getManager();
  798.         $dem $this->doctrine->getManager('dynamic_em');
  799.          
  800.         /* we get user */ 
  801.         $userId $session->get('user')->getUserId();
  802.         $user $em->getRepository(User::class)->getUser($userId);
  803.         
  804.         /* we get current e-shop */
  805.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  806.  
  807.         /* we get product parameter group */
  808.         $contactGroup $dem->getRepository(ContactGroup::class)->getContactGroup($contactGroupId);
  809.         $userDirs $this->getUserFolderPaths($request);
  810.         
  811.         /*
  812.         print('<br>QQW categoryCollection: ');
  813.         \Doctrine\Common\Util\Debug::dump($categoryCollection);
  814.         */
  815.           
  816.         /* we build edit form */
  817.         $formBuilder $this->createFormBuilder($contactGroup);
  818.         $formBuilder->add('contactGroupName'TextType::class, array(
  819.                 'required' => true,
  820.                 'label' => $this->translator->trans('knowledgebase.contact_group_name'),
  821.                 'attr' => array('class' => 'text_form''size' => 22'value' => $contactGroup->getContactGroupName()),
  822.                 'label_attr' => array('class' => 'form_field_label'),
  823.         ));         
  824.        
  825.          $formBuilder->add('contactGroupBoard'TextareaType::class, array(
  826.                 'required' => false,
  827.                 'label' => $this->translator->trans('knowledgebase.contact_group_board'),
  828.                 'attr' => array('class' => 'textarea_form''cols' => 77'rows' => 7'value' => $contactGroup->getContactGroupBoard()),
  829.                 'label_attr' => array('class' => 'form_field_label'),
  830.                 'data' => $contactGroup->getContactGroupBoard(),
  831.         )); 
  832.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  833.                 'attr' => array('class' => 'butt_big')));
  834.          
  835.         $form $formBuilder->getForm();
  836.          
  837.         $form->handleRequest($request);
  838.          
  839.         if ($request->getMethod() == 'POST') {
  840.              
  841.             //$form->bindRequest($request);
  842.              
  843.             if ($form->isValid()) {
  844.                 // perform some action, such as save the object to the database
  845.                 $formData $form->getData();
  846.         
  847.                 $contactGroup->setContactGroupName($formData->getContactGroupName());
  848.                 $contactGroup->setContactGroupBoard($formData->getContactGroupBoard());
  849.                 /* we persist and save */
  850.                 $dem->persist($contactGroup);
  851.                 $dem->flush();
  852.                 $this->addFlash('notice''Contact group was updated.');
  853.                 return $this->redirectToRoute('contactGroupEdit', array('contactGroupId' => $contactGroup->getContactGroupId()));
  854.                  
  855.             }
  856.              
  857.         }
  858.         /* we render data */
  859.         return $this->render('contactGroupEdit.html.twig',
  860.             array('headerData' => $this -> getPageHeader($request),
  861.                   'form' => $formBuilder->getForm()->createView(),
  862.                   'contactGroup' => $contactGroup,
  863.                   'userDirs' => $userDirs,
  864.                   'menu' => $this -> adminMenu($request),
  865.                   'user' => $user,
  866.                   'mainMenu' => $this -> adminMainMenu($request)
  867.                 )
  868.         );        
  869.     }
  870.     /**
  871.      * @Route("/contactGroupRemove/{contactGroupId}", name="contactGroupRemove")
  872.      */
  873.     public function contactGroupRemoveAction(Request $request$contactGroupId)
  874.     {
  875.         /* we load session data */
  876.         parent::init($request);
  877.         $session $request->getSession();
  878.         
  879.         /* we load entity managers */
  880.         $em $this->doctrine->getManager();
  881.         $dem $this->doctrine->getManager('dynamic_em');
  882.          
  883.         /* we get user */ 
  884.         $userId $session->get('user')->getUserId();
  885.         $user $em->getRepository(User::class)->getUser($userId);
  886.         
  887.         /* we get current e-shop */
  888.         $eshop $em->getRepository(Eshop::class)->getCurrentEshop($userId);
  889.  
  890.         /* we get product parameter group */
  891.         $contactGroup $dem->getRepository(ContactGroup::class)->getContactGroup($contactGroupId);
  892.         //we remove association from contacts
  893.         $contactList $dem->getRepository(Contact::class)->getContactList();
  894.         foreach($contactList as $contact) {
  895.             
  896.             $contactGroupList $contact->getContactGroups();
  897.             foreach($contactGroupList as $group) {
  898.                 if ($group->getContactGroupId() == $contactGroupId) {
  899.                     
  900.                     //print('<br>contact: '.$contact->getContactId());
  901.                     $contact->removeContactGroup($group);
  902.                 }
  903.             }
  904.         }
  905.         //we remove ContactGroup object
  906.         $dem->remove($contactGroup);
  907.         $dem->flush();   
  908.         $this->addFlash('notice''Contact group was removed.');
  909.         return $this->redirectToRoute('contacts');
  910.     }
  911.     
  912.     /**
  913.      * @Route("/lists", name="lists")
  914.      */
  915.     public function listsAction(Request $request)
  916.     {
  917.         /* we load session data */
  918.         parent::init($request);
  919.         $session $request->getSession();
  920.         // we check if any user is logged in
  921.         if(!$this->isLoggedUser($request)) {
  922.             return $this->redirectToRoute('login');
  923.         } 
  924.         /* we load entity managers */
  925.         $em $this->doctrine->getManager();
  926.         $dem $this->doctrine->getManager('dynamic_em');
  927.         /* we get user */
  928.         $userId $session->get('user')->getUserId();
  929.         $user $em->getRepository(User::class)->getUser($userId);
  930.         /* we check if user is logged in */
  931.         if(empty($session->get('user'))) {
  932.             return $this->redirectToRoute('login');
  933.         }          
  934.         /* we get file name and paths */
  935.         $userDirs $this->getUserFolderPaths($request);        
  936.     
  937.         $customLists $dem->getRepository(CustomList::class)->getCustomLists();
  938.         /* we build search form */
  939.         $formBuilder $this->createFormBuilder();
  940.         $searchString null;
  941.         $searchResult null;
  942.     
  943.         $formBuilder->add('searchString'TextType::class, array(
  944.                 'required' => true,
  945.                 'label' => ' ',
  946.                 'attr' => array('class' => 'text_form''size' => 22),
  947.                 'label_attr' => array('class' => 'form_field_label22'),
  948.         ));
  949.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('system.search'),
  950.                 'attr' => array('class' => 'inlineButton')));
  951.     
  952.         $form $formBuilder->getForm();
  953.         $form->handleRequest($request);
  954.     
  955.         if ($request->getMethod() == 'POST') {
  956.     
  957.             if ($form->isValid()) {
  958.                 $searchString $request->request->get('form')['searchString'];
  959.                 $searchResult['listItems'] = $dem->getRepository(CustomListItem::class)->getCustomListItemBySearch(trim($searchString));
  960.     
  961.                 $this->addFlash('notice''Searched string:'.$searchString);
  962.             }
  963.              
  964.         }
  965.         /* we render data */
  966.         return $this->render('lists.html.twig',
  967.                 array(    'form' => $formBuilder->getForm()->createView(),
  968.                         'headerData' => $this -> getPageHeader($request),
  969.                         'customLists' => $customLists,
  970.                         'menu' => $this -> adminMenu($request),
  971.                         'userDirs' => $userDirs,
  972.                         'searchResult' => $searchResult,    
  973.                         'searchString' => $searchString,
  974.                         'user' => $user,
  975.                         'mainMenu' => $this -> adminMainMenu($request)
  976.                 )
  977.                 );
  978.     
  979.     }    
  980.     
  981.    /**
  982.      * @Route("/listnew", name="listNew")
  983.      */
  984.     public function listNewAction(Request $request)
  985.     {
  986.         /* we load session data */
  987.         parent::init($request);
  988.     
  989.         $session $request->getSession();
  990.     
  991.         $em $this->doctrine->getManager();
  992.         /* we get user */
  993.         $userId $session->get('user')->getUserId();
  994.         $user $em->getRepository(User::class)->getUser($userId);
  995.     
  996.         /* we build login form */
  997.         $list = new CustomList();
  998.         $formBuilder $this->createFormBuilder($list);
  999.         $formBuilder->add('listName'TextType::class, array(
  1000.                 'required' => true,
  1001.                 'label' => $this->translator->trans('knowledgebase.list_name'),
  1002.                 'attr' => array('class' => 'text_form''size' => 22),
  1003.                 'label_attr' => array('class' => 'form_field_label'),
  1004.         ));
  1005.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  1006.                 'attr' => array('class' => 'butt_big')));
  1007.     
  1008.         $form $formBuilder->getForm();
  1009.         $form->handleRequest($request);
  1010.     
  1011.         if ($request->getMethod() == 'POST') {
  1012.     
  1013.             if ($form->isValid()) {
  1014.                 // perform some action, such as save the object to the database
  1015.                 /* we load users entity manager */
  1016.                 $dem $this->doctrine->getManager('dynamic_em');
  1017.                 $formData $form->getData();
  1018.                 print('<br>qqw saving data');
  1019.                 \Doctrine\Common\Util\Debug::dump($formData);
  1020.                 $list->setListName($formData->getListName());
  1021.                 /* we persist and save */
  1022.                 $dem->persist($list);
  1023.                 $dem->flush();
  1024.     
  1025.                 $this->addFlash('notice''New list was created.');
  1026.                  
  1027.                 return $this->redirectToRoute('listEdit', array('listId' => $list->getListId()));
  1028.     
  1029.             }
  1030.              
  1031.         }
  1032.     
  1033.         /* we render data */
  1034.         return $this->render('listNew.html.twig',
  1035.                 array(    'form' => $formBuilder->getForm()->createView(),
  1036.                         'headerData' => $this -> getPageHeader($request),
  1037.                         'menu' => $this -> adminMenu($request),
  1038.                         'user' => $user,
  1039.                         'mainMenu' => $this -> adminMainMenu($request)
  1040.                 )
  1041.                 );
  1042.     
  1043.     }       
  1044.     
  1045.     /**
  1046.      * @Route("/listedit/{listId}", name="listEdit")
  1047.      */
  1048.     public function listEditAction(Request $request$listId)
  1049.     {
  1050.         /* we load session data */
  1051.         parent::init($request);
  1052.         $session $request->getSession();
  1053.         // we check if any user is logged in
  1054.         if(!$this->isLoggedUser($request)) {
  1055.             return $this->redirectToRoute('login');
  1056.         }   
  1057.     
  1058.         /* we load users entity manager */
  1059.         $em $this->doctrine->getManager();
  1060.         $dem $this->doctrine->getManager('dynamic_em');
  1061.     
  1062.         $userId $session->get('user')->getUserId();
  1063.         $user $em->getRepository(User::class)->getUser($userId);
  1064.         /* removing list item */
  1065.         if(!empty($request->query->get('removeListItem'))) {
  1066.             $listItem $dem->getRepository(CustomListItem::class)->removeCustomListItem($request->query->get('removeListItem'));
  1067.             $this->addFlash('notice''List item was removed.');
  1068.         }  
  1069.         if(!empty($request->query->get('saveXml'))) {  
  1070.             //print('<br>qqw saving xml');
  1071.             $this->saveListXML($request$listId);
  1072.             $this->addFlash('notice''List was exported to XML.');
  1073.         }      
  1074.     
  1075.         $list $dem->getRepository(CustomList::class)->getCustomList($listId);
  1076.         $listItems $dem->getRepository(CustomListItem::class)->getCustomListItems($listId);
  1077.         /* we get file name and paths */
  1078.         $userDirs $this->getUserFolderPaths($request);
  1079.         /*
  1080.         print('<br>QQW list ID: '.$listId);
  1081.         \Doctrine\Common\Util\Debug::dump($list);
  1082.         */
  1083.     
  1084.         /* we build form for new items */
  1085.         $listItem = new CustomListItem();
  1086.         $formNewItemsBuilder $this->createFormBuilder($listItem);
  1087.         $formNewItemsBuilder->add('listItemName'TextType::class, array(
  1088.                 'required' => true,
  1089.                 'label' => $this->translator->trans('knowledgebase.new_list_item'),
  1090.                 'attr' => array('class' => 'text_form_file2''size' => 35'value' => ''),
  1091.                 'label_attr' => array('class' => 'form_field_label'),
  1092.         )); 
  1093.         $formNewItemsBuilder->add('listItemShortDescription'TextType::class, array(
  1094.                 'required' => false,
  1095.                 'label' => $this->translator->trans('knowledgebase.list_short_description'),
  1096.                 'attr' => array('class' => 'text_form_file2''size' => 35'value' => ''),
  1097.                 'label_attr' => array('class' => 'form_field_label'),
  1098.         ));   
  1099.         $formNewItemsBuilder->add('listItemLongDescription'TextareaType::class, array(
  1100.                 'required' => false,
  1101.                 'label' => $this->translator->trans('knowledgebase.list_item_long_description'),
  1102.                 'attr' => array('class' => 'textarea_form''cols' => 50'rows' => 3'value' => ''),
  1103.                 'label_attr' => array('class' => 'form_textarea_label'),
  1104.         ));         
  1105.         $formNewItemsBuilder->add('clickURL'TextType::class, array(
  1106.                 'required' => false,
  1107.                 'label' => $this->translator->trans('system.link_url'),
  1108.                 'attr' => array('class' => 'text_form_file2''size' => 35'value' => ''),
  1109.                 'label_attr' => array('class' => 'form_field_label'),
  1110.         ));               
  1111.         $formNewItemsBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('knowledgebase.create_list_item'),
  1112.                 'attr' => array('class' => 'butt_big')));  
  1113.         /* we build edit form */
  1114.         $formBuilder $this->createFormBuilder($list);
  1115.     
  1116.         $formBuilder->add('listName'TextType::class, array(
  1117.                 'required' => false,
  1118.                 'label' => $this->translator->trans('knowledgebase.list_name'),
  1119.                 'attr' => array('class' => 'text_form''size' => 35'value' => $list->getListName()),
  1120.                 'label_attr' => array('class' => 'form_field_label')
  1121.         ));
  1122.         $formBuilder->add('linkURL'TextType::class, array(
  1123.                 'required' => false,
  1124.                 'label' => $this->translator->trans('system.link_url'),
  1125.                 'attr' => array('class' => 'text_form''size' => 35'value' => $list->getLinkURL()),
  1126.                 'label_attr' => array('class' => 'form_field_label')
  1127.         ));   
  1128.         $formBuilder->add('xmlFile'TextType::class, array(
  1129.                 'required' => false,
  1130.                 'label' => $this->translator->trans('system.xml_file'),
  1131.                 'attr' => array('class' => 'text_form''size' => 25'value' => $list->getXmlFile()),
  1132.                 'label_attr' => array('class' => 'form_field_label')
  1133.         ));  
  1134.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  1135.                 'attr' => array('class' => 'butt_big')));
  1136.         if ($request->getMethod() == 'POST') {
  1137.             $formNewItems $formNewItemsBuilder->getForm();
  1138.             $formNewItems->handleRequest($request);
  1139.             if ($formNewItems->isValid()) {
  1140.                 $formNewItemsData $formNewItems->getData();
  1141.                 
  1142.                 /* we load users entity manager */
  1143.                 //$dem = $this->doctrine->getManager('dynamic_em');
  1144.                 $listItem->setListItemName($formNewItemsData->getListItemName());
  1145.                 $listItem->setListItemShortDescription($formNewItemsData->getListItemShortDescription());
  1146.                 $listItem->setListItemLongDescription($formNewItemsData->getListItemLongDescription());
  1147.                 $listItem->setClickURL($formNewItemsData->getClickURL());
  1148.                 $listItem->setListId($listId);
  1149.                 /* we persist and save */
  1150.                 $dem->persist($listItem);
  1151.                 $dem->flush();
  1152.                 $this->addFlash('notice''New Item was Created');
  1153.                 
  1154.                 return $this->redirectToRoute('listEdit', array('listId' => $listId));               
  1155.                 
  1156.             }
  1157.             $form $formBuilder->getForm();
  1158.             $form->handleRequest($request);
  1159.             if ($form->isValid()) {
  1160.                 $formData $form->getData();
  1161.     
  1162.                 /* we load data from form into contact object */
  1163.                 $list->setListName($formData->getListName());
  1164.                 $list->setXmlFile($formData->getXmlFile());
  1165.                 $list->setLinkURL($formData->getLinkURL());
  1166.                 /* we persist and save */
  1167.                 //$em->persist($contact);
  1168.                 $dem->flush();
  1169.     
  1170.                 $this->addFlash('notice''List was updated.');
  1171.     
  1172.                 return $this->redirectToRoute('listEdit', array('listId' => $list->getListId()));
  1173.     
  1174.             }
  1175.     
  1176.         }
  1177.     
  1178.         /* we render data */
  1179.         return $this->render('listEdit.html.twig',
  1180.                 array(  'headerData' => $this -> getPageHeader($request),
  1181.                         'formNewItems' => $formNewItemsBuilder->getForm()->createView(),
  1182.                         'form' => $formBuilder->getForm()->createView(),
  1183.                         'list' => $list,
  1184.                         'listItems' => $listItems,
  1185.                         'userDirs' => $userDirs,
  1186.                         'user' => $user,
  1187.                         'menu' => $this -> adminMenu($request),
  1188.                         'mainMenu' => $this -> adminMainMenu($request)
  1189.                 )
  1190.                 );
  1191.     
  1192.     }      
  1193.     public function saveListXML(Request $request$listId)
  1194.     { 
  1195.         /* we load session data */
  1196.         parent::init($request);
  1197.         $session $request->getSession();
  1198.     
  1199.         /* we load users entity manager */
  1200.         $dem $this->doctrine->getManager('dynamic_em');
  1201.     
  1202.         $userId $session->get('user')->getUserId();
  1203.         //print('<br>user id: '.$userId);
  1204.         //die('<br>qqw 22 user id: ');          
  1205.     
  1206.         $list $dem->getRepository(CustomList::class)->getCustomList($listId);
  1207.         $listItems $dem->getRepository(CustomListItem::class)->getCustomListItems($listId);
  1208.         if(!$this->isUserFolder($request)) {
  1209.             $this->createUserFolder($request);
  1210.         }
  1211.         /* we get file name and paths */
  1212.         $userDirs $this->getUserFolderPaths($request);
  1213.         if(!empty($list->getXmlFile())) {
  1214.             $fileName $list->getXmlFile();
  1215.         } else {
  1216.             $fileName "list_".$listId.".xml";
  1217.         }
  1218.         /*
  1219.         print('<br>QQW list ID: '.$listId);
  1220.         \Doctrine\Common\Util\Debug::dump($list);
  1221.         */
  1222.         $xmlDocument = new \DOMDocument('1.0''UTF-8');
  1223.         $style 
  1224.             list { display: block; padding-left: 10px; }
  1225.             listItem {
  1226.                 display: block; 
  1227.             }
  1228.             listItem:hover {
  1229.                 display: block;
  1230.                 background-color: #EFEFEF;  
  1231.             }
  1232.             .listItemTitle {
  1233.                 display: inline-block;
  1234.                 /* width: 300px; */
  1235.                 width: 45%;
  1236.                 height: 22px;
  1237.                 padding: 1px;
  1238.                 border: #DDD solid 1px; 
  1239.                 background-color: #EFEFEF;
  1240.             }
  1241.             listItemShortDescription {
  1242.                 display: inline-block;
  1243.                 /* width: 300px; */
  1244.                 width: 45%;
  1245.                 height: 22px;   
  1246.                 padding: 1px;
  1247.                 border: #DDD solid 1px; 
  1248.                 /*  background-color: #EFEFEF;  */
  1249.             }
  1250.             listTitle {
  1251.              font-family : Arial, Helvetica, sans-serif;
  1252.              display: block;
  1253.              font-size : 22px; 
  1254.              font-weight : bold;
  1255.              padding-top: 5px;
  1256.              padding-bottom: 5px; 
  1257.              height: 22px;
  1258.             }
  1259.             listItemAttribute1 {
  1260.              font-family : Arial, Helvetica, sans-serif;
  1261.              display: block;
  1262.              font-size : 22px; 
  1263.              font-weight : bold;
  1264.              padding-top: 5px;
  1265.              padding-bottom: 5px; 
  1266.              height: 22px;
  1267.             }    
  1268.             
  1269.             listItemAttribute2 {
  1270.              font-family : Arial, Helvetica, sans-serif;
  1271.              display: block;
  1272.              font-size : 22px; 
  1273.              font-weight : bold;
  1274.              padding-top: 5px;
  1275.              padding-bottom: 5px; 
  1276.              height: 22px;
  1277.             }                      
  1278.         ";
  1279.         $css $xmlDocument->createProcessingInstruction("xml-stylesheet""type=\"text/css\" href=\"https://www.vrcommerce.cz/css/list1.css\"");
  1280.         //$css = $xmlDocument->createProcessingInstruction("xml-stylesheet", "type=\"text/css\" href=\"#style\"");
  1281.         $xmlDocument->appendChild($css); 
  1282.         $rootElement $xmlDocument->createElement('list');
  1283.         $titleTag $xmlDocument->createElement('listTitle'$list->getListName());
  1284.         //$titleTag->setAttribute("class", "listTitle");
  1285.         //$titleTag->setAttribute("style", "background-color: #EFEFEF;");
  1286.         $rootElement->appendChild($titleTag);
  1287.         //$styleTag = $xmlDocument->createElement('style', $style);
  1288.         //$styleTag->setAttribute("type", "text/css");
  1289.         //$styleTag->setAttribute("id", "style");
  1290.         //<style type = "text/css">
  1291.         //$rootElement->appendChild($styleTag);
  1292.         $listItemsTag $xmlDocument->createElement('listItems');
  1293.         foreach($listItems as $listItem) {
  1294.             $listItemsTag $xmlDocument->createElement('listItem');
  1295.             $listItemsTitleTag $xmlDocument->createElement('listItemTitle'$listItem->getListItemName()); 
  1296.             $listItemsShortDescriptionTag $xmlDocument->createElement('listItemShortDescription'$listItem->getListItemShortDescription()); 
  1297.             $listItemsTag->appendChild($listItemsTitleTag);
  1298.             $listItemsTag->appendChild($listItemsShortDescriptionTag);
  1299.             $listItemsLongDescriptionTag $xmlDocument->createElement('listItemLongDescription');
  1300.             $listItemsLongDescriptionTag->appendChild($xmlDocument->createCDATASection(html_entity_decode(strip_tags($listItem->getListItemLongDescription()))));
  1301.             $listItemsTag->appendChild($listItemsLongDescriptionTag);  
  1302.             $listItemsAttribute1Tag $xmlDocument->createElement('listItemAttribute1'$listItem->getFreeProperty1()); 
  1303.             $listItemsAttribute2Tag $xmlDocument->createElement('listItemAttribute2'$listItem->getFreeProperty2()); 
  1304.             $listItemsTag->appendChild($listItemsAttribute1Tag);  
  1305.             $listItemsTag->appendChild($listItemsAttribute2Tag);  
  1306.             $rootElement->appendChild($listItemsTag); 
  1307.         }
  1308.         $xmlDocument->appendChild($rootElement);
  1309.         $xmlDocument->saveXML();
  1310.         $xmlDocument->save($userDirs['user'].'/'.$fileName);
  1311.         $list->setXmlFile($fileName);
  1312.         $dem->persist($list);
  1313.         $dem->flush();
  1314.         /*
  1315.         $response = new Response($xmlDocument->saveXML());
  1316.         $response->headers->set('Content-Type', 'xml');
  1317.         */
  1318.         
  1319.         //return $response;
  1320.     
  1321.         /* we render data */
  1322.         /*
  1323.         return $this->render('listXML.html.php',
  1324.                 array(  'headerData' => $this -> getPageHeader($request),
  1325.                         'list' => $list,
  1326.                         'listItems' => $listItems,
  1327.                 )
  1328.                 );
  1329.         */
  1330.     
  1331.     }          
  1332.     /**
  1333.      * @Route("/listitemedit/{listItemId}", name="listItemEdit")
  1334.      */
  1335.     public function listItemEditAction(Request $request$listItemId)
  1336.     {
  1337.         /* we load session data */
  1338.         parent::init($request);
  1339.         $session $request->getSession();
  1340.         // we check if any user is logged in
  1341.         if(!$this->isLoggedUser($request)) {
  1342.             return $this->redirectToRoute('login');
  1343.         }   
  1344.     
  1345.         /* we load users entity manager */
  1346.         $em $this->doctrine->getManager();
  1347.         $dem $this->doctrine->getManager('dynamic_em');
  1348.     
  1349.         $userId $session->get('user')->getUserId();
  1350.         $user $em->getRepository(User::class)->getUser($userId);
  1351.     
  1352.         $listItem $dem->getRepository(CustomListItem::class)->getCustomListItem($listItemId);
  1353.         $list $dem->getRepository(CustomList::class)->getCustomList($listItem->getListId());
  1354.         /*
  1355.         print('<br>QQW list ID: '.$listId);
  1356.         \Doctrine\Common\Util\Debug::dump($list);
  1357.         */
  1358.         /* we build edit form */
  1359.         $formBuilder $this->createFormBuilder($listItem);
  1360.     
  1361.         $formBuilder->add('listItemName'TextType::class, array(
  1362.                 'required' => false,
  1363.                 'label' => $this->translator->trans('knowledgebase.list_item_name'),
  1364.                 'attr' => array('class' => 'text_form''size' => 35'value' => $listItem->getListItemName()),
  1365.                 'label_attr' => array('class' => 'form_field_label')
  1366.         ));
  1367.         $formBuilder->add('listItemShortDescription'TextareaType::class, array(
  1368.                 'required' => false,
  1369.                 'label' => $this->translator->trans('knowledgebase.list_item_short_description'),
  1370.                 'attr' => array('class' => 'textarea_form''cols' => 55'rows' => 4'value' => $listItem->getListItemShortDescription()),
  1371.                 'label_attr' => array('class' => 'form_textarea_label'),
  1372.                 'data' => $listItem->getListItemShortDescription(),
  1373.         ));      
  1374.         $formBuilder->add('clickURL'TextType::class, array(
  1375.                 'required' => false,
  1376.                 'label' => $this->translator->trans('system.link_url'),
  1377.                 'attr' => array('class' => 'text_form''size' => 53'value' => $listItem->getClickURL()),
  1378.                 'label_attr' => array('class' => 'form_field_label')
  1379.         ));         
  1380.         $formBuilder->add('listItemLongDescription'TextareaType::class, array(
  1381.                 'required' => false,
  1382.                 'label' => $this->translator->trans('knowledgebase.list_item_long_description'),
  1383.                 'attr' => array('class' => 'textarea_form''cols' => 101'rows' => 5'value' => $listItem->getListItemLongDescription()),
  1384.                 'label_attr' => array('class' => 'form_textarea_label'),
  1385.                 'data' => $listItem->getListItemLongDescription(),
  1386.         )); 
  1387.         $formBuilder->add('freeProperty1'TextType::class, array(
  1388.                 'required' => false,
  1389.                 'label' => $this->translator->trans('knowledgebase.list_item_free_property1'),
  1390.                 'attr' => array('class' => 'text_form''size' => 53'value' => $listItem->getFreeProperty1()),
  1391.                 'label_attr' => array('class' => 'form_field_label')
  1392.         ));      
  1393.         $formBuilder->add('freeProperty2'TextType::class, array(
  1394.                 'required' => false,
  1395.                 'label' => $this->translator->trans('knowledgebase.list_item_free_property2'),
  1396.                 'attr' => array('class' => 'text_form''size' => 53'value' => $listItem->getFreeProperty2()),
  1397.                 'label_attr' => array('class' => 'form_field_label')
  1398.         ));               
  1399.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  1400.                 'attr' => array('class' => 'butt_big')));
  1401.         $form $formBuilder->getForm();
  1402.         $form->handleRequest($request);
  1403.     
  1404.         if ($request->getMethod() == 'POST') {
  1405.             if ($form->isValid()) {
  1406.                 // perform some action, such as save the object to the database
  1407.                 //print('<br>qqw post form 2: ');
  1408.                 $formData $form->getData();
  1409.     
  1410.                 /* we load data from form into contact object */
  1411.                 $listItem->setListItemName($formData->getListItemName());
  1412.                 $listItem->setListItemShortDescription($formData->getListItemShortDescription());
  1413.                 $listItem->setListItemLongDescription($formData->getListItemLongDescription());
  1414.                 $listItem->setClickURL($formData->getClickURL());
  1415.                 $listItem->setFreeProperty1($formData->getFreeProperty1());
  1416.                 $listItem->setFreeProperty2($formData->getFreeProperty2());
  1417.                 /* we persist and save */
  1418.                 //$em->persist($contact);
  1419.                 $dem->flush();
  1420.     
  1421.                 $this->addFlash('notice''List item was updated.');
  1422.     
  1423.                 return $this->redirectToRoute('listEdit', array('listId' => $listItem->getListId()));
  1424.     
  1425.             }
  1426.     
  1427.         }
  1428.     
  1429.         /* we render data */
  1430.         return $this->render('listItemEdit.html.twig',
  1431.                 array(  'headerData' => $this -> getPageHeader($request),
  1432.                         'form' => $formBuilder->getForm()->createView(),
  1433.                         'list' => $list,
  1434.                         'listItem' => $listItem,
  1435.                         'menu' => $this -> adminMenu($request),
  1436.                         'user' => $user,
  1437.                         'mainMenu' => $this -> adminMainMenu($request)
  1438.                 )
  1439.                 );
  1440.     
  1441.     }    
  1442.     /**
  1443.      * @Route("/tradeLead", name="tradeLead")
  1444.      */
  1445.     public function tradeLeadAction(Request $request)
  1446.     {
  1447.     
  1448.         /* we load session data */
  1449.         parent::init($request);
  1450.         $session $request->getSession();
  1451.     
  1452.         /* we load users entity manager */
  1453.         $em $this->doctrine->getManager();
  1454.         $dem $this->doctrine->getManager('dynamic_em');
  1455.         $userId $session->get('user')->getUserId();
  1456.         $user $em->getRepository(User::class)->getUser($userId);
  1457.         /* removing tradelead */
  1458.         if(!empty($request->query->get('removeLead'))) {   
  1459.             $tradeLead $dem->getRepository(TradeLead::class)->findOneBy(['tradeLeadId' => $request->query->get('removeLead')]);
  1460.             if(!empty($tradeLead)) {
  1461.                 try {
  1462.                     
  1463.                     $dem->remove($tradeLead);        
  1464.                     //$em->persist($tradeLead);
  1465.                     $dem->flush();
  1466.                     //$tradeLead = $dem->getRepository(TradeLead::class)->removeTradeLead($request->query->get('removeLead'));
  1467.                     $this->addFlash('notice''Trade Lead was removed.');
  1468.                 } catch(\Doctrine\DBAL\DBALException $e) {
  1469.                     $this->addFlash('error'"This Trade Lead has connected services (orders etc.), so it can't be removed.");
  1470.                 }                
  1471.             }
  1472.             
  1473.         }         
  1474.         /* import tradelead */
  1475.         if(!empty($request->query->get('importLeads'))) {   
  1476.             print('<br>qqw import leads');
  1477.             ini_set('max_execution_time'1800); 
  1478.             set_time_limit(1800);
  1479.             $mem $this->doctrine->getManager('marketplace_em');
  1480.             $marketplaceConn $mem->getConnection('marketplace_conn');
  1481.             $sql "SELECT * FROM eshops e INNER JOIN eshops_description ed ON e.id_shop = ed.id_shop AND ed.title != ''";
  1482.             $stmt $marketplaceConn->prepare($sql);
  1483.             $stmt->execute();
  1484.             $result $stmt->fetchAll();
  1485.             foreach($result as $row) {
  1486.                 print('<hr>row: ');
  1487.                 \Doctrine\Common\Util\Debug::dump($row);
  1488.                 $tradeLead $dem->getRepository(TradeLead::class)->findOneBy(array('externalId' => $row['id_shop']));
  1489.                 if(empty($tradeLead)) {
  1490.                     $tradeLead = new TradeLead;
  1491.                 }
  1492.                 $tradeLead->setTitle($row['title']);
  1493.                 $tradeLead->setDescription($row['description']);
  1494.                 $tradeLead->setNotes($row['notes']);
  1495.                 $tradeLead->setEmail($row['email']);  
  1496.                 $tradeLead->setStatus($row['status']);              
  1497.                 $tradeLead->setContactPersonEmail($row['email_director']);   
  1498.                 $tradeLead->setLinkUrl($row['url']);  
  1499.                 $tradeLead->setExternalId($row['id_shop']);  
  1500.                 print('<br>tradeLead: ');
  1501.                 \Doctrine\Common\Util\Debug::dump($tradeLead);
  1502.    
  1503.                 /* we persist and save */
  1504.                 $dem->persist($tradeLead);
  1505.                 $dem->flush();
  1506.             }
  1507.             
  1508.         } 
  1509.     
  1510.         $tradeLeadList $dem->getRepository(TradeLead::class)->findAll();
  1511.         /* we render data */
  1512.         return $this->render('tradeLeads.html.twig',
  1513.                 array(  'headerData' => $this -> getPageHeader($request),
  1514.                         'tradeLeadList' => $tradeLeadList,
  1515.                         'menu' => $this -> adminMenu($request),
  1516.                         'user' => $user,
  1517.                         'mainMenu' => $this -> adminMainMenu($request)
  1518.                 )
  1519.                 );
  1520.     
  1521.     }    
  1522.     /**
  1523.      * @Route("/tradeLeadExec", name="tradeLeadExec")
  1524.      */
  1525.     public function tradeLeadExecAction(Request $request)
  1526.     {
  1527.     
  1528.         /* we load session data */
  1529.         parent::init($request);
  1530.         $session $request->getSession();
  1531.     
  1532.         /* we load users entity manager */
  1533.         $em $this->doctrine->getManager();
  1534.         $dem $this->doctrine->getManager('dynamic_em');
  1535.         /* we get user */ 
  1536.         $userId $session->get('user')->getUserId();
  1537.         $user $em->getRepository(User::class)->getUser($userId);
  1538.         $userDirs $this->getUserFolderPaths($request);
  1539.         $selectedTradeLeads = array();
  1540.         if(!empty($request->request->get('selectedTradeLeads'))) {
  1541.             //print(' tradeleads POSTED');
  1542.             $selectedTradeLeads $request->request->get('selectedTradeLeads');
  1543.             $leadList json_encode($selectedTradeLeads);
  1544.             //\Doctrine\Common\Util\Debug::dump($request->request->get('selectedTradeLeads'));
  1545.         }
  1546.         if(!empty($request->request->get('form')['leadList'])) {
  1547.             $leadList $request->request->get('form')['leadList'];
  1548.         }
  1549.         $emailSubject '';
  1550.         if(!empty($request->request->get('form')['emailSubject'])) {
  1551.             $emailSubject $request->request->get('form')['emailSubject'];
  1552.         }
  1553.         $emailBodyHtml '';
  1554.         if(!empty($request->request->get('form')['emailBodyHtml'])) {
  1555.             $emailBodyHtml $request->request->get('form')['emailBodyHtml'];
  1556.         }       
  1557.         //Doctrine\Common\Util\Debug::dump($request->request->get('selectedTradeLeads'));
  1558.         //$tradeLeadList = $dem->getRepository(TradeLead::class)->findAll();
  1559.         
  1560.        
  1561.         /* we build edit form */
  1562.         $formBuilder $this->createFormBuilder();
  1563.         $formBuilder->add('emailSubject'TextType::class, array(
  1564.                 'required' => false,
  1565.                 'label' => 'email subject',
  1566.                 'attr' => array('class' => 'text_form''size' => 70'value' => $emailSubject),
  1567.                 'label_attr' => array('class' => 'form_field_label'),
  1568.         ));         
  1569.        
  1570.          $formBuilder->add('emailBodyHtml'CKEditorType::class, array(
  1571.                 'required' => false,
  1572.                 'label' => 'html email',
  1573.                 'attr' => array('class' => 'text_form''size' => 35'value' => $emailBodyHtml),
  1574.                 'label_attr' => array('class' => 'form_field_label'),
  1575.                 'data' => $emailBodyHtml,
  1576.         )); 
  1577.         $formBuilder->add('leadList'HiddenType::class, array(
  1578.                 'data' => $leadList,
  1579.         ));         
  1580.         $formBuilder->add('save'SubmitType::class, array('label' => 'Execute Action',
  1581.                 'attr' => array('class' => 'butt_big')));
  1582.          
  1583.         $form $formBuilder->getForm();
  1584.          
  1585.         $form->handleRequest($request);
  1586.          
  1587.         if ($request->getMethod() == 'POST') {
  1588.              
  1589.             //$form->bindRequest($request);
  1590.              
  1591.             if ($form->isValid()) {
  1592.                 // perform some action, such as save the object to the database
  1593.                 //print('<br>tradeleads ids json: ');
  1594.                 //print_r($request->request->get('form')['selectedTradeLeads']);
  1595.                 $leadIdList json_decode($request->request->get('form')['leadList']);
  1596.                 foreach($leadIdList as $leadId) {
  1597.                     
  1598.                     $tradeLead $dem->getRepository(TradeLead::class)->findOneBy(array('tradeLeadId' => $leadId));
  1599.                     print('<hr>executing on lead: '.$tradeLead->getTitle().' , id: '.$leadId);
  1600.                     //Doctrine\Common\Util\Debug::dump($tradeLead);
  1601.                     //print_r($tradeLead);
  1602.                     $now = new \DateTime();
  1603.                     $nowDate $now->format('Y-m-d H:i:s'); 
  1604.                     if(!empty($tradeLead->getEmail())) {
  1605.                         $to $tradeLead->getEmail();
  1606.                         $subject $emailSubject;
  1607.                         $message $emailBodyHtml;
  1608.                         $name $user->getCompany();
  1609.                         $from $user->getEmail();
  1610.                         $headers  "MIME-Version: 1.0\r\n";
  1611.                         $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  1612.                         $headers .= "From: {$name} <{$from}>\r\n";
  1613.                         $headers .= "Reply-To: <{$from}>\r\n";
  1614.                         $headers .= "Subject: {$subject}\r\n";
  1615.                         $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
  1616.                         
  1617.                         /* we send email to e-shop admin */
  1618.                         if(@mail($to$subject$message$headers)) {
  1619.                             $message '['.$nowDate.'] Email `'.$emailSubject.'` was sent to: '.$to;
  1620.                             print('<br>'.$message);
  1621.                             $tradeLead->setNotes($tradeLead->getNotes()."\n".$message);
  1622.                         } else {
  1623.                             print('<br>Email was not sent to: '.$to);
  1624.                         }   
  1625.                     }
  1626.                     if(!empty($tradeLead->getContactPersonEmail())) {
  1627.                         $to $tradeLead->getContactPersonEmail();
  1628.                         $subject $emailSubject;
  1629.                         $message $emailBodyHtml;
  1630.                         $name $user->getCompany();
  1631.                         $from $user->getEmail();
  1632.                         $headers  "MIME-Version: 1.0\r\n";
  1633.                         $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  1634.                         $headers .= "From: {$name} <{$from}>\r\n";
  1635.                         $headers .= "Reply-To: <{$from}>\r\n";
  1636.                         $headers .= "Subject: {$subject}\r\n";
  1637.                         $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
  1638.                         
  1639.                         /* we send email to e-shop admin */
  1640.                         if(@mail($to$subject$message$headers)) {
  1641.                             $message '['.$nowDate.'] Email `'.$emailSubject.'` was sent to: '.$to;
  1642.                             print('<br>'.$message);
  1643.                             $tradeLead->setNotes($tradeLead->getNotes()."\n".$message);
  1644.                         } else {
  1645.                             print('<br>Email was not sent to: '.$to); 
  1646.                         }   
  1647.                     }  
  1648.                     $dem->persist($tradeLead);
  1649.                     $dem->flush();                  
  1650.                 }
  1651.                 //Doctrine\Common\Util\Debug::dump($request->request->get('form')['emailSubject']);
  1652.                 $this->addFlash('notice''Trade Lead Action was executed.');
  1653.                  
  1654.             }
  1655.              
  1656.         }        
  1657.         /* we render data */
  1658.         return $this->render('tradeLeadExec.html.php',
  1659.                 array(  'headerData' => $this -> getPageHeader($request),
  1660.                         'form' => $formBuilder->getForm()->createView(),
  1661.                         'selectedTradeLeads' => $selectedTradeLeads,
  1662.                         'leadList' => $leadList,                        
  1663.                         'menu' => $this -> adminMenu($request),
  1664.                         'mainMenu' => $this -> adminMainMenu($request)
  1665.                 )
  1666.                 );
  1667.     
  1668.     }        
  1669.     /**
  1670.      * @Route("/tradeleadedit/{tradeLeadId}", name="tradeLeadEdit")
  1671.      */
  1672.     public function tradeLeadEditAction(Request $request$tradeLeadId)
  1673.     {
  1674.         /* we load session data */
  1675.         parent::init($request);
  1676.         $session $request->getSession();
  1677.     
  1678.         /* we load entity managers */
  1679.         $em $this->doctrine->getManager();
  1680.         $dem $this->doctrine->getManager('dynamic_em');
  1681.     
  1682.         $userId $session->get('user')->getUserId();
  1683.         $user $em->getRepository(User::class)->getUser($userId);
  1684.     
  1685.         $tradeLead $dem->getRepository(TradeLead::class)->findOneBy(array('tradeLeadId' => $tradeLeadId));
  1686.         /* removing tradelead */
  1687.         if(!empty($request->query->get('createEshopLink'))) {  
  1688.             print('<br>createEshopLink ...');
  1689.             $eshopLink = new EshopLink;
  1690.             $eshopLink->setEshopLinkName($tradeLead->getTitle());
  1691.             $eshopLink->setEshopLinkUrl($tradeLead->getLinkUrl());
  1692.             $eshopLink->addLanguage($session->get('lang'));
  1693.             $em->persist($eshopLink);
  1694.             $em->flush();                     
  1695.             $this->addFlash('notice''New Eshop Link was created.');
  1696.         }
  1697.         /* we build edit form */ 
  1698.         $formBuilder $this->createFormBuilder($tradeLead);
  1699.     
  1700.         $formBuilder->add('title'TextType::class, array(
  1701.                 'required' => false,
  1702.                 'label' => $this->translator->trans('marketplace.trade_lead_title'),
  1703.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getTitle()),
  1704.                 'label_attr' => array('class' => 'form_field_label')
  1705.         ));
  1706.         
  1707.         $formBuilder->add('company'TextType::class, array(
  1708.                 'required' => false,
  1709.                 //'label' => $this->translator->trans('knowledgebase.middle_name'),
  1710.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getCompany()),
  1711.                 'label_attr' => array('class' => 'form_field_label')
  1712.         ));     
  1713.         
  1714.         $formBuilder->add('email'TextType::class, array(
  1715.                 'required' => false,
  1716.                 //'label' => $this->translator->trans('knowledgebase.last_name'),
  1717.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getEmail()),
  1718.                 'label_attr' => array('class' => 'form_field_label')
  1719.         ));  
  1720.         $formBuilder->add('linkUrl'TextType::class, array(
  1721.                 'required' => false,
  1722.                 //'label' => $this->translator->trans('knowledgebase.middle_name'),
  1723.                 'attr' => array('class' => 'text_form''size' => 91'value' => $tradeLead->getLinkUrl()),
  1724.                 'label_attr' => array('class' => 'form_field_label')
  1725.         ));            
  1726.         $formBuilder->add('description'TextareaType::class, array(
  1727.                 'required' => false,
  1728.                 //'label' => $this->translator->trans('knowledgebase.list_item_short_description'),
  1729.                 'attr' => array('class' => 'textarea_form''cols' => 90'rows' => 10'value' => $tradeLead->getDescription()),
  1730.                 'label_attr' => array('class' => 'form_textarea_label'),
  1731.                 'data' => $tradeLead->getDescription(),
  1732.         ));  
  1733.         $formBuilder->add('notes'TextareaType::class, array(
  1734.                 'required' => false,
  1735.                 //'label' => $this->translator->trans('knowledgebase.list_item_short_description'),
  1736.                 'attr' => array('class' => 'textarea_form''cols' => 90'rows' => 10'value' => $tradeLead->getNotes()),
  1737.                 'label_attr' => array('class' => 'form_textarea_label'),
  1738.                 'data' => $tradeLead->getNotes(),
  1739.         ));  
  1740.         $formBuilder->add('contactPerson'TextType::class, array(
  1741.                 'required' => false,
  1742.                 //'label' => $this->translator->trans('knowledgebase.company_name'),
  1743.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getContactPerson()),
  1744.                 'label_attr' => array('class' => 'form_field_label')
  1745.         ));         
  1746.         $formBuilder->add('contactPersonEmail'TextType::class, array(
  1747.                 'required' => false,
  1748.                 //'label' => $this->translator->trans('knowledgebase.email'),
  1749.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getContactPersonEmail()),
  1750.                 'label_attr' => array('class' => 'form_field_label')
  1751.         ));           
  1752.         $formBuilder->add('telephone'TextType::class, array(
  1753.                 'required' => false,
  1754.                 //'label' => $this->translator->trans('knowledgebase.email'),
  1755.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getTelephone()),
  1756.                 'label_attr' => array('class' => 'form_field_label')
  1757.         ));         
  1758.         $formBuilder->add('address'TextType::class, array(
  1759.                 'required' => false,
  1760.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1761.                 'attr' => array('class' => 'text_form''size' => 91'value' => $tradeLead->getAddress()),
  1762.                 'label_attr' => array('class' => 'form_field_label')
  1763.         ));   
  1764.         $formBuilder->add('invoiceAddress'TextType::class, array(
  1765.                 'required' => false,
  1766.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1767.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getInvoiceAddress()),
  1768.                 'label_attr' => array('class' => 'form_field_label')
  1769.         ));  
  1770.         $formBuilder->add('responsibleAdminUserId'TextType::class, array(
  1771.                 'required' => false,
  1772.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1773.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getResponsibleAdminUserId()),
  1774.                 'label_attr' => array('class' => 'form_field_label')
  1775.         ));  
  1776.         $formBuilder->add('dateResponsibilityGiven'TextType::class, array(
  1777.                 'required' => false,
  1778.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1779.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getDateResponsibilityGiven()),
  1780.                 'label_attr' => array('class' => 'form_field_label')
  1781.         ));  
  1782.         $formBuilder->add('status'TextType::class, array(
  1783.                 'required' => false,
  1784.                 //label' => $this->translator->trans('knowledgebase.phone'),
  1785.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getStatus()),
  1786.                 'label_attr' => array('class' => 'form_field_label')
  1787.         ));  
  1788.         $formBuilder->add('serverId'TextType::class, array(
  1789.                 'required' => false,
  1790.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1791.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getServerId()),
  1792.                 'label_attr' => array('class' => 'form_field_label')
  1793.         ));  
  1794.         $formBuilder->add('areaId'TextType::class, array(
  1795.                 'required' => false,
  1796.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1797.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getAreaId()),
  1798.                 'label_attr' => array('class' => 'form_field_label')
  1799.         ));  
  1800.         $formBuilder->add('preferredSectionId'TextType::class, array(
  1801.                 'required' => false,
  1802.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1803.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getPreferredSectionId()),
  1804.                 'label_attr' => array('class' => 'form_field_label')
  1805.         ));  
  1806.         $formBuilder->add('preferredSectionId2'TextType::class, array(
  1807.                 'required' => false,
  1808.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1809.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getPreferredSectionId2()),
  1810.                 'label_attr' => array('class' => 'form_field_label')
  1811.         ));  
  1812.         $formBuilder->add('avatarUrl'TextType::class, array(
  1813.                 'required' => false,
  1814.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1815.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getAvatarUrl()),
  1816.                 'label_attr' => array('class' => 'form_field_label')
  1817.         ));  
  1818.         $formBuilder->add('logoUrl'TextType::class, array(
  1819.                 'required' => false,
  1820.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1821.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getLogoUrl()),
  1822.                 'label_attr' => array('class' => 'form_field_label')
  1823.         ));  
  1824.         $formBuilder->add('bankAccount'TextType::class, array(
  1825.                 'required' => false,
  1826.                 //'label' => $this->translator->trans('knowledgebase.phone'),
  1827.                 'attr' => array('class' => 'text_form''size' => 35'value' => $tradeLead->getBankAccount()),
  1828.                 'label_attr' => array('class' => 'form_field_label')
  1829.         ));                                                                          
  1830.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  1831.                 'attr' => array('class' => 'butt_big')));
  1832.     
  1833.         $form $formBuilder->getForm();
  1834.         $form->handleRequest($request);
  1835.     
  1836.         if ($request->getMethod() == 'POST') {
  1837.             if ($form->isValid()) {
  1838.                 $formData $form->getData();
  1839.     
  1840.                 /* we load data from form into TradeLead object */
  1841.                 $tradeLead->setTitle($formData->getTitle());
  1842.                 $tradeLead->setCompany($formData->getCompany());
  1843.                 $tradeLead->setEmail($formData->getEmail());
  1844.                 $tradeLead->setLinkUrl($formData->getLinkUrl());
  1845.                 $tradeLead->setContactPerson($formData->getContactPerson());
  1846.                 $tradeLead->setContactPersonEmail($formData->getContactPerson());
  1847.                 $tradeLead->setTelephone($formData->getTelephone());
  1848.                 $tradeLead->setNotes($formData->getNotes());
  1849.                 $tradeLead->setDescription($formData->getDescription());
  1850.                 $tradeLead->setAddress($formData->getAddress());
  1851.                 $tradeLead->setInvoiceAddress($formData->getInvoiceAddress());
  1852.                 $tradeLead->setResponsibleAdminUserId($formData->getResponsibleAdminUserId());
  1853.                 //$tradeLead->setDateResponsibilityGiven($request->request->get('form')['dateResponsibilityGiven']);                
  1854.                 $tradeLead->setStatus($formData->getStatus());
  1855.                 $tradeLead->setServerId($formData->getServerId());
  1856.                 $tradeLead->setAreaId($formData->getAreaId());
  1857.                 $tradeLead->setPreferredSectionId($formData->getPreferredSectionId());
  1858.                 $tradeLead->setPreferredSectionId2($formData->getPreferredSectionId2());
  1859.                 $tradeLead->setAvatarUrl($formData->getAvatarUrl());
  1860.                 $tradeLead->setLogoUrl($formData->getLogoUrl());
  1861.                 $tradeLead->setBankAccount($formData->getBankAccount());
  1862.                 /* we persist and save */
  1863.                 $dem->persist($tradeLead);
  1864.                 $dem->flush();
  1865.     
  1866.                 $this->addFlash('notice''Trade Lead was updated.');
  1867.     
  1868.                 return $this->redirectToRoute('tradeLeadEdit', array('tradeLeadId' => $tradeLead->getTradeLeadId()));
  1869.     
  1870.             }
  1871.     
  1872.         }
  1873.     
  1874.         /* we render data */
  1875.         return $this->render('tradeLeadEdit.html.twig',
  1876.                 array(  'headerData' => $this -> getPageHeader($request),
  1877.                         'form' => $formBuilder->getForm()->createView(),
  1878.                         'tradeLead' => $tradeLead,
  1879.                         'menu' => $this -> adminMenu($request),
  1880.                         'mainMenu' => $this -> adminMainMenu($request),
  1881.                         'user' => $user
  1882.                 )
  1883.                 );
  1884.     
  1885.     }   
  1886.     /**
  1887.      * @Route("/tradeLeadNew", name="tradeLeadNew")
  1888.      */
  1889.     public function tradeLeadNewAction(Request $request)
  1890.     {
  1891.         /* we load session data */
  1892.         parent::init($request);
  1893.     
  1894.         $session $request->getSession();
  1895.         /* we load users entity manager */
  1896.         $em $this->doctrine->getManager();
  1897.         $dem $this->doctrine->getManager('dynamic_em');
  1898.         $userId $session->get('user')->getUserId();
  1899.         $user $em->getRepository(User::class)->getUser($userId);
  1900.     
  1901.         /* we build login form */
  1902.         $tradeLead = new TradeLead();
  1903.         $formBuilder $this->createFormBuilder($tradeLead);
  1904.     
  1905.         $formBuilder->add('title'TextType::class, array(
  1906.                 'required' => true,
  1907.                 'label' => $this->translator->trans('marketplace.trade_lead_title'),
  1908.                 'attr' => array('class' => 'text_form''size' => 22),
  1909.                 'label_attr' => array('class' => 'form_field_label'),
  1910.         ));
  1911.         
  1912.         $formBuilder->add('save'SubmitType::class, array('label' => $this->translator->trans('form.button.save'),
  1913.                 'attr' => array('class' => 'butt_big')));
  1914.     
  1915.         $form $formBuilder->getForm();
  1916.         $form->handleRequest($request);
  1917.     
  1918.         if ($request->getMethod() == 'POST') {
  1919.     
  1920.             if ($form->isValid()) {
  1921.                 // perform some action, such as save the object to the database
  1922.     
  1923.                 /* we load users entity manager */
  1924.                 $dem $this->doctrine->getManager('dynamic_em');
  1925.                 $formData $form->getData();
  1926.                 $tradeLead->setTitle($formData->getTitle());
  1927.                 /* we persist and save */
  1928.                 $dem->persist($tradeLead);
  1929.                 $dem->flush();
  1930.     
  1931.                 $this->addFlash('notice''New Trade lead was created.');
  1932.                  
  1933.                 return $this->redirectToRoute('tradeLeadEdit', array('tradeLeadId' => $tradeLead->getTradeLeadId()));
  1934.     
  1935.             }
  1936.              
  1937.         }
  1938.     
  1939.         /* we render data */
  1940.         return $this->render('tradeLeadNew.html.twig',
  1941.                 array(  'form' => $formBuilder->getForm()->createView(),
  1942.                         'headerData' => $this -> getPageHeader($request),
  1943.                         'menu' => $this -> adminMenu($request),
  1944.                         'mainMenu' => $this -> adminMainMenu($request),
  1945.                         'user' => $user
  1946.                 )
  1947.                 );
  1948.     
  1949.     }
  1950.     
  1951.     public function adminMenu(Request $request)
  1952.     {
  1953.         $menuItems = array(
  1954.           => array('link' => 'knowledgebaseAdmin''langKey' => 'knowledgebase.admin''routeName' => 'knowledgebaseAdmin'),
  1955.           => array('link' => 'contacts''langKey' => 'knowledgebase.contacts''routeName' => 'contacts'),
  1956.           => array('link' => 'contactnew''langKey' => 'knowledgebase.new_contact''routeName' => 'contactNew'),
  1957.           => array('link' => 'tasks''langKey' => 'knowledgebase.tasks''routeName' => 'tasks'),
  1958.           => array('link' => 'tasknew''langKey' => 'knowledgebase.new_task''routeName' => 'taskNew'),                
  1959.           => array('link' => 'lists''langKey' => 'knowledgebase.lists''routeName' => 'lists'),
  1960.           => array('link' => 'listnew''langKey' => 'knowledgebase.new_list''routeName' => 'listNew'),
  1961.         );
  1962.         return $menuItems;
  1963.     }
  1964.     
  1965. }