<?php
namespace App\Controller;
use Doctrine\Persistence\ManagerRegistry;
//use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\Routing\Annotation\Route;
//use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Doctrine\Persistence\ManagerRegistry as PersistenceManagerRegistry;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use App\Entity\Department;
use App\Entity\Language;
use App\Entity\Server;
use App\Entity\Service;
use App\Entity\ShoppingWindow;
use App\Entity\User;
use App\Entity\UserStory;
use App\Entity\Module;
use App\Entity\Order;
use App\Entity\EshopLink;
use App\Entity\Feed;
use App\Entity\FormResponse;
class ScreenController extends DefaultController
{
protected string $databaseUser = "root";
protected string $databasePassword = "pswdb33";
/** KernelInterface $appKernel */
protected $appKernel;
protected $translator;
public function __construct(KernelInterface $appKernel,
ManagerRegistry $doctrine,
TranslatorInterface $translator)
{
$this->appKernel = $appKernel;
$this->doctrine = $doctrine;
$this->translator = $translator;
}
#[Route('/', name: 'root')]
public function indexAction(Request $request, ManagerRegistry $doctrine) {
/* we load session data */
parent::init($request, $doctrine);
$session = $request->getSession();
$em = $this->doctrine->getManager();
//print('<br>QQW session: '.$session->get('server')->getLabel());
//$translator->trans('symfony.great');
$homePage = '';
//$homePage = $this->parseContent($request, "{INTERACTIVESLIDESHOW_3}");
if(!empty($session->get('user'))) {
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
} else {
$user = null;
}
// we get root departments
$rootDepartments = $em->getRepository(Department::class)->getRootNodes();
// we add sub departments
$subDepartments = array();
foreach($rootDepartments as $dep)
{
$depId = $dep->getDepartmentId();
$dep->setLocale($session->get('lang')->getLangKey());
$em->refresh($dep);
// print('<br>departmentId: '.$depId);
// print('<br>departmentName: '.$dep->getDepartmentName());
$subDeps = $em->getRepository(Server::class)->getSubDepartments($depId);
$subDepartments[$depId] = $subDeps;
}
/* we load list of departments for marketplace service */
$departmentArray[] = $em->getRepository(Server::class)->getDepartment(3);
/* we load list of shopping windows */
$shoppingWindowList = $em->getRepository(ShoppingWindow::class)->getShoppingWindowList($departmentArray, 0, 6);
$templatesDir = $this->appKernel->getProjectDir() . '/app/Resources/views';
$serviceIcons = [];
foreach($session->get('server')->getServices() as $service) {
$serviceId = $service->getServiceId();
$icon3d = '/users/Kantona/freeworld/FUTURE_'.$this->getNormalisedText($service->getServiceName());
$icon3d = $icon3d.'.x3d';
//if($session->get('label') == 'webexciter.com') {
//$icon3d = $icon3d.'.x3d';
//} else {
//$icon3d = $icon3d.'-White.x3d';
//}
//echo "<br>The file:".$icon3d;
if (is_file('.'.$icon3d)) {
//echo "<br>The file $icon3d exists";
$serviceIcons[$serviceId] = $icon3d;
}
}
$server_request_scheme = 'https';
$uri = $server_request_scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if (strpos($uri, 'app_dev.php') == false) {
$urlBase = '/';
} else {
$urlBase = $server_request_scheme . '://' . $_SERVER['HTTP_HOST'] . '/';
}
$eCommerceNews = $this->getRedactionList($request, 1);
/*
print('<br>Server: ');
\Doctrine\Common\Util\Debug::dump($session->get('server'));
*/
/* we render data */
return $this->render('index.html.twig',
array('headerData' => $this -> getPageHeader($request),
'homePage' => $homePage,
'user' => $user,
'rootDepartments' => $rootDepartments,
'subDepartments' => $subDepartments,
'shoppingWindowList' => $shoppingWindowList,
'templatesDir' => $templatesDir,
'serviceIcons' => $serviceIcons,
'uri' => $uri,
'urlBase' => $urlBase,
'eCommerceNews' => $eCommerceNews,
)
);
}
#[Route('/login', name: 'login')]
public function loginAction(Request $request, ManagerRegistry $doctrine) {
/* we load session data */
parent::init($request, $doctrine);
$em = $this->doctrine->getManager();
$user = new User();
/* we build login form */
$formBuilder = $this->createFormBuilder($user);
/*
$formBuilder->add('username', TextType::class, [
'required' => true,
'label' => $this->translator->trans('user.username')
]);
*/
$formBuilder->add('username', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('user.username'),
'attr' => array('class' => 'simple_text_form', 'size' => 22),
'label_attr' => array('class' => 'simple_form_field_label'),
));
$formBuilder->add('psw', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password'),
'attr' => array('class' => 'simple_text_form', 'size' => 22),
'label_attr' => array('class' => 'simple_form_field_label'),
));
$formBuilder->add('save', SubmitType::class, array('label' => 'Login',
'attr' => array('class' => 'butt_big')));
//$formBuilder->add('save', SubmitType::class, ['label' => 'Login']);
$form = $formBuilder->getForm();
/*
$form = $this->createFormBuilder()
->add('task', TextType::class)
->add('save', SubmitType::class, ['label' => 'Create Task'])
->getForm();
*/
$form->handleRequest($request);
//print('<br>Form: ');
//\Doctrine\Common\Util\Debug::dump($form);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
$em = $this->doctrine->getManager();
$formData = $form->getData();
if (!empty($request->request->get('username'))) {
$loginUserName = $request->request->get('username');
$isHashedLogin = true;
} else {
$loginUserName = $formData->getUserName();
$isHashedLogin = false;
}
if(!empty($request->request->get('password'))) {
$loginPsw = $request->request->get('password');
} else {
$loginPsw = $formData->getPsw();
}
if(!empty($loginUserName) && !empty($loginPsw)) {
//print('<br>qqw login 001a');
if ($isHashedLogin) {
$userExist = $em->getRepository(User::class)->getUserFromHashedLogin($loginUserName, $loginPsw);
} else {
$userExist = $em->getRepository(User::class)->getUserFromLogin($loginUserName, $loginPsw);
}
}
//print('<br>userExist: '.$loginUserName.' :: '.$loginPsw);
//die();
/* we check if this username exists */
if(!empty($userExist)) {
/* we load logged user into session */
$session = $request->getSession();
$session->set('user', $userExist);
/*
print('<hr>we set session user: ');
\Doctrine\Common\Util\Debug::dump($session->get('user'));
*/
$flashMessage = $this->translator->trans('system.welcome').' '.$loginUserName.'. '.$this->translator->trans('system.you_are_logged');
$this->addFlash('notice', $flashMessage);
$userExist->setLastLogin(new \DateTime());
$em->persist($userExist);
$em->flush();
// we redirect to request route or to homeuser
if(!empty($userExist->getServices()) && count($userExist->getServices())==1 ) {
foreach($userExist->getServices() as $service) {
return $this->redirectToRoute($service->getLandingUrl().'Admin');
}
} else {
return $this->redirectToRoute('homeuser');
}
}
else {
$this->addFlash('error', 'Login error.');
}
//}
}
/* we render data */
return $this->render('login.html.twig',
array('form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request)
)
);
}
/**
* @Route("/homeuser", name="homeuser")
*/
#[Route('/homeuser', name: 'homeuser')]
public function homeuserAction(Request $request) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
// we check if any user is logged in
if(!$this->isLoggedUser($request)) {
return $this->redirectToRoute('login');
}
/* we load entity managers */
$em = $this->doctrine->getManager();
$dem = $this->doctrine->getManager('dynamic_em');
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
$userDirs = $this->getUserFolderPathsFromUserId($userId);
$moduleCollection = $em->getRepository(Module::class)->getModuleList();
/* we check users database */
if(!$this->checkUserDB($request)) {
return $this->redirectToRoute('homeuser');
}
/* we check user entities */
$this->checkUserEntities($request);
//$this->generateUserEntities($request);
/* we load dynamic entity manager */
//$dem = $this->doctrine->getManager('dynamic_em');
//return $this->redirectToRoute('eshopAdmin');
$orderList = null;
$orderPrices = array();
$eshopService = $em->getRepository(Service::class)->getService(1);
$isService = $em->getRepository(User::class)->userHasService($user, $eshopService);
if($isService) {
/* we load recent orders */
//$orderList = $dem->getRepository(Order::class)->getOrderList("orderId", "DESC", 5);
$orderList = [];
if(!empty($orderList) && count($orderList) > 0) {
/* we get current e-shop */
$eshop = $em->getRepository('AppBundle:Eshop')->getCurrentEshop($userId);
if(!empty($eshop)) {
$defaultCurrency = $em->getRepository('AppBundle:Currency')->getCurrency($eshop->getPreferredCurrencyId());
}
}
/* we load order prices */
foreach($orderList as $order) {
if(!empty($order->getCurrencyKey())) {
$targetCurrency = $em->getRepository('AppBundle:Currency')->getCurrencyByKey($order->getCurrencyKey());
} else {
$targetCurrency = $defaultCurrency;
}
$orderPrices[$order->getOrderId()] = $dem->getRepository('AppBundle:Order')->getOrderPrice($order->getOrderId(), $targetCurrency, false, $eshop, $defaultCurrency);
}
}
//we check if user has Form Builder module and get recent form responses
$module = $em->getRepository(Module::class)->getModule(12);
$isModule = $em->getRepository(User::class)->userHasModule($user, $module);
$formResponseList = null;
if($isModule) {
//print('<br>qqw is Form Builder');
$formResponseList = $dem->getRepository(FormResponse::class)->getFormResponseList2("formResponseId", "DESC", 5);
//$formResponseList = $dem->getRepository('AppBundle:FormResponse')->getFormResponseList();
}
//we check if user has UserStory module and get recent form responses
$module = $em->getRepository(Module::class)->getModule(24);
$isModule = $em->getRepository(User::class)->userHasModule($user, $module);
$taskList = null;
if($isModule) {
$dateStart = date("Y-m-d",strtotime('monday this week'));
$dateEnd = date("Y-m-d",strtotime('sunday this week'));
$taskList = $dem->getRepository(UserStory::class)->getUserStoryStartBetweenDatesList($dateStart, $dateEnd);
}
/*
$serverExist = $em->getRepository('AppBundle:Server')->getServerFromLabel('webexciter.com');
print('<br>QQW Current server: ');
\Doctrine\Common\Util\Debug::dump($serverExist);
print('<hr>QQW UD: ');
\Doctrine\Common\Util\Debug::dump($userDirs);
*/
/* we render data */
return $this->render('homeuser.html.twig',
array('headerData' => $this -> getPageHeader($request),
'user' => $user,
'orderList' => $orderList,
'orderPrices' => $orderPrices,
'formResponseList' => $formResponseList,
'userDirs' => $userDirs,
'taskList' => $taskList,
'menu' => $this -> adminMenu($request),
'mainMenu' => $this -> adminMainMenu($request),
'moduleCollection' => $moduleCollection
)
);
}
#[Route('/homeuser/config', name: 'config')]
public function configAction(Request $request) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
// we check if any user is logged in
if(!$this->isLoggedUser($request)) {
return $this->redirectToRoute('login');
}
$em = $this->doctrine->getManager();
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
$serviceCollection = $em->getRepository(Service::class)->getServiceList();
/*
print('<br>QQW user ID: '.$userId);
\Doctrine\Common\Util\Debug::dump($user);
*/
/*
$serverExist = $em->getRepository('AppBundle:Server')->getServerFromLabel('webexciter.com');
print('<br>QQW Current server: ');
\Doctrine\Common\Util\Debug::dump($serverExist);
print('<hr>QQW Current user: ');
\Doctrine\Common\Util\Debug::dump($session->get('user'));
*/
/* we build register form */
$formBuilder = $this->createFormBuilder($user);
$formBuilder->add('company', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.company'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $user->getCompany()),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('email', EmailType::class, array(
'required' => true,
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $user->getEmail()),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('contactPersonEmail', EmailType::class, array(
'required' => false,
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $user->getContactPersonEmail()),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('telephone', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.telephone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $user->getTelephone()),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('address', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('user.address'),
'attr' => array('class' => 'textarea_form', 'cols' => 33, 'rows' => 2, 'value' => $user->getAddress()),
'label_attr' => array('class' => 'form_textarea_label'),
'data' => $user->getAddress(),
));
$formBuilder->add('bankAccount', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.bank_account'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $user->getBankAccount()),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('ico', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.business_number'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $user->getIco()),
'label_attr' => array('class' => 'form_field_label'),
));
/* we add service list */
$services = array();
foreach($serviceCollection as $service)
{
$serviceId = $service->getServiceId();
$services[$service->getServiceName()] = $service->getServiceId();
}
$selectedServices = array();
foreach($user->getServices() as $service)
{
$selectedServices[] = $service->getServiceId();
}
$formBuilder->add('services', ChoiceType::class, array(
'choices' => $services,
'required' => false,
'mapped' => false,
'multiple' => true,
'expanded' => true,
'data' => $selectedServices
));
// if is module email provider
$module = $em->getRepository(Module::class)->getModule(40);
$isModule = $em->getRepository(User::class)->userHasModule($user, $module);
/*
if($isModule) {
$formBuilder->add('emailProviderName', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.company'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $user->getCompany()),
'label_attr' => array('class' => 'form_field_label')
));
}
*/
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('form.send'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
if ($form->isValid()) {
// perform some action, such as save the object to the database
//print('<br>qqw post form 2: ');
$formData = $form->getData();
//print('<br>We create new user');
//$user = new User;
/* we load user data from register form into user object */
$user->setCompany($formData->getCompany());
$user->setEmail($formData->getEmail());
$user->setContactPersonEmail($formData->getContactPersonEmail());
$user->setTelephone($formData->getTelephone());
$user->setAddress($formData->getAddress());
$user->setBankAccount($formData->getBankAccount());
$user->setIco($formData->getIco());
/* we remove old service associations */
foreach($user->getServices() as $service) {
$user->removeService($service);
//$session->get('user')->removeService($service);
}
/* we load user services */
$formServices = $form['services']->getData();
if(!empty($formServices)) {
foreach($formServices as $serviceId) {
$addService = $em->getRepository(Service::class)->getService($serviceId);
$user->addService($addService);
//$session->get('user')->addService($addService);
}
}
/*
print('<br>qqw user exists: ');
\Doctrine\Common\Util\Debug::dump($user);
*/
/* we persist and save user *//* we persist and save user */
$em->persist($user);
$em->flush();
/* we update user session */
$session->set('user', $user);
$this->addFlash('notice', 'User was updated.');
return $this->redirectToRoute('config');
}
}
/* we render data */
return $this->render('userConfig.html.twig',
array( 'form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request)
)
);
}
#[Route('/moduleInfo', name: 'moduleInfo')]
public function moduleInfoAction(Request $request) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
// we check if any user is logged in
if(!$this->isLoggedUser($request)) {
return $this->redirectToRoute('login');
}
$em = $this->doctrine->getManager();
$userId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($userId);
$serviceCollection = $em->getRepository(Service::class)->getServiceList();
/* we render data */
return $this->render('moduleInfo.html.php',
array( 'headerData' => $this -> getPageHeader($request)
)
);
}
/**
* @Route("/newaccount", name="newaccount")
*/
#[Route('/newaccount', name: 'newaccount')]
public function newAccountAction(Request $request) {
/* we load session data */
parent::init($request);
$session = $request->getSession();
$em = $this->doctrine->getManager();
$serviceCollection = $em->getRepository(Service::class)->getServiceList();
$user = new User();
$server = $this->getServerByLabel($session->get('label'));
/* we prepare data for the form */
if(!empty($request->request->get('form2')['company'])) {
$company = $request->request->get('form')['company'];
} else {
$company = '';
}
if(!empty($request->request->get('form2')['email'])) {
$email = $request->request->get('form2')['email'];
} else {
$email = '';
}
if(!empty($request->request->get('form2')['telephone'])) {
$telefon = $request->request->get('form2')['telephone'];
} else {
$telefon = '';
}
if(!empty($request->request->get('form2')['address'])) {
$address = $request->request->get('form2')['address'];
} else {
$address = '';
}
if(!empty($request->request->get('form2')['username'])) {
$username = $request->request->get('form2')['username'];
} else {
$username = '';
}
if(!empty($request->request->get('form2')['password'])) {
$password = $request->request->get('form2')['password'];
} else {
$password = '';
}
if(!empty($request->request->get('form2')['password_retype'])) {
$password_retype = $request->request->get('form2')['password_retype'];
} else {
$password_retype = '';
}
/* we build register form */
$formBuilder = $this->createFormBuilder($user);
// $formBuilder->add('save2', SubmitType::class, array('label' => $this->translator->trans('system.register'),
// 'attr' => array('class' => 'butt_big')));
$formBuilder->add('company', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.company'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $company),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('email', EmailType::class, array(
'required' => true,
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $email),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('telephone', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.telephone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $telefon),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('address', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('user.address'),
'attr' => array('class' => 'textarea_form', 'cols' => 33, 'rows' => 2, 'value' => $address),
'label_attr' => array('class' => 'form_textarea_label'),
));
$formBuilder->add('username', TextType::class, array(
'required' => true,
'label' => $this->translator->trans('user.username'),
'empty_data' => '',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $username),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('psw', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('psw_retype', PasswordType::class, array(
'required' => true,
'label' => $this->translator->trans('user.password_retype'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $password_retype),
'label_attr' => array('class' => 'form_field_label_required'),
'mapped' => false
));
$formBuilder->add('control_question', TextType::class, array(
'required' => true,
'label' => '7 + 4 =',
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => ''),
'label_attr' => array('class' => 'form_field_label_control_question'),
'mapped' => false
));
//die('<br>qqw post form 0: ');
// we add service list
// we add preselected service registrations
$selectedServices = [];
if(!empty($session->get('eshopLink'))) {
$selectedServices[] = 4;
}
if(!empty($request->get('addService'))) {
$selectedServices[] = $request->get('addService');
}
// we add preselected module registrations
if(!empty($request->get('addModule'))) {
$selectedServices[] = 'module_'.$request->get('addModule');
}
// we add second preselected module registrations
if(!empty($request->get('addModule2'))) {
$selectedServices[] = 'module_'.$request->get('addModule2');
}
$services = array();
$serviceCount = 0;
foreach($serviceCollection as $service)
{
$serviceId = $service->getServiceId();
$localisedServiceName = $this->translator->trans('service.'.$service->getAction());
$services[$localisedServiceName] = $service->getServiceId();
$serviceModules = $service->getModules();
$moduleArray = array();
if(!empty($serviceModules)) {
foreach($serviceModules as $mod) {
$services[$mod->getModuleName()] = 'module_'.$mod->getModuleId();
}
}
$serviceCount++;
}
// we sort the array - selected services first
$sortedServices = array();
foreach($selectedServices as $key => $serviceId)
{
foreach($serviceCollection as $service)
{
if ($service->getServiceId() == $serviceId) {
$localisedServiceName = $this->translator->trans('service.'.$service->getAction());
$sortedServices[$localisedServiceName] = $service->getServiceId();
$serviceModules = $service->getModules();
$moduleArray = array();
if(!empty($serviceModules)) {
foreach($serviceModules as $mod) {
$sortedServices[$mod->getModuleName()] = 'module_'.$mod->getModuleId();
}
}
}
}
}
// we add other not checked services
foreach($serviceCollection as $service)
{
if (!in_array($service->getServiceId(), $sortedServices)) {
$localisedServiceName = $this->translator->trans('service.'.$service->getAction());
$sortedServices[$localisedServiceName] = $service->getServiceId();
$serviceModules = $service->getModules();
$moduleArray = array();
if(!empty($serviceModules)) {
foreach($serviceModules as $mod) {
$sortedServices[$mod->getModuleName()] = 'module_'.$mod->getModuleId();
}
}
}
}
$services = $sortedServices;
//print('<hr>qqw selectedServices: ');
//var_dump($selectedServices);
$formBuilder->add('services', ChoiceType::class, array(
'choices' => $services,
'required' => false,
'label' => $this->translator->trans('service.services'),
'attr' => array('class' => 'form_choice'),
'label_attr' => array('class' => 'form_choice_label'),
'label_format' => 'form.address.%name%',
//'choice_name' => 'texteditor',
'choice_attr' => function($val, $key, $index) {
// adds a class like attending_yes, attending_no, etc
$pos = strpos($val, 'module');
if ($pos === false) {
$cssClass = 'service-item';
} else {
$cssClass = 'module-item';
}
return ['class' => $cssClass];
},
'mapped' => false,
'multiple' => true,
'expanded' => true,
'data' => $selectedServices
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('system.register_free'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//print('<br>qqw post form 1: ');
$formData = $form->getData();
//$form->bindRequest($request);
if(!empty($server->getGoogleApiKey()) && $server->getGoogleApiKey() !== '') {
//we load re-captcha
$captchaResponse = $request->get('g-recaptcha-response');
} else {
$captchaResponse = "noCaptcha";
}
$controlQuestion = (int)$form['control_question']->getData();
if ($form->isValid() && $captchaResponse != "" && $controlQuestion == 11) {
// perform some action, such as save the object to the database
print('<br>qqw post form 2: ');
/* we check if this username already exists */
$em = $this->doctrine->getManager();
$formData = $form->getData();
$userExist = $em->getRepository(User::class)->getUserFromUsername($formData->getUserName());
// print('<br>qqw user exists: ');
// \Doctrine\Common\Util\Debug::dump($userExist);
if($userExist === null) {
/* we check if the password fields are the same */
$password = $formData->getPsw();
//$retypePassword = $formData->get('psw_retype');
$retypePassword = $form['psw_retype']->getData();
$hashPassword = md5($password);
/*
print('<br>qqw password: '.$password);
print('<br>qqw retypePassword: '.$retypePassword);
print('<br>qqw hashPassword: '.$hashPassword);
*/
if ($password != '' && $password == $retypePassword) {
//print('<br>We create new user');
$newUser = new User;
$password = md5($formData->getPsw());
/* we load user data from register form into user object */
$newUser->setCompany($formData->getCompany());
$newUser->setUserName($formData->getUserName());
$newUser->setEmail($formData->getEmail());
$newUser->setAddress($formData->getAddress());
$newUser->setPsw($password);
$user->setPsw($password);
$newUser->setDatabaseUser($this->databaseUser);
$newUser->setDatabasePassword($this->databasePassword);
$newUser->setDateInserted(new \DateTime());
$user->setDateInserted(new \DateTime());
$servicesString = "";
$modulesString = "";
/* we load user services */
$formServices = $form['services']->getData();
if(!empty($formServices)) {
foreach($formServices as $key=>$serviceId) {
$pos = strpos($serviceId, 'module');
if ($pos === false) {
//we add service to user
$addService = $em->getRepository(Service::class)->getService($serviceId);
$user->addService($addService);
$servicesString .= $addService->getServiceName(). " | ";
} else {
//we add module to user
$moduleExplode = explode("_", $serviceId);
$addModule = $em->getRepository(Module::class)->getModule($moduleExplode[1]);
$user->addModule($addModule);
$modulesString .= $addModule->getModuleName(). " | ";
}
}
}
/* we persist and save user */
$em->persist($user);
$em->flush();
//die("<br>qqw die");
/*
print('<br>qqw user exists: ');
\Doctrine\Common\Util\Debug::dump($user);
*/
/* we add preselected service registrations */
if(!empty($session->get('eshopLink'))) {
print('<br>qqw eshopLink: ');
\Doctrine\Common\Util\Debug::dump($session->get('eshopLink'));
/*
if(!empty($session->get('eshopLink')->getDepartments())) {
foreach($session->get('eshopLink')->getDepartments() as $dep) {
print('<hr>qqw eshopLink department: ');
\Doctrine\Common\Util\Debug::dump($dep);
}
}
*/
$moduleId = 11;
$addModule = $em->getRepository(Module::class)->getModule($moduleId);
$user->addModule($addModule);
$eshopLink = $session->get('eshopLink');
$userExist = $em->getRepository(User::class)->getUserFromUsername($request->request->get('form')['username']);
$eshopLink->setUserId($userExist->getUserId());
print('<br>qqw eshopLink: ');
\Doctrine\Common\Util\Debug::dump($eshopLink->getDepartments());
/* we persist associated eshop link departments */
if(!empty($eshopLink->getDepartments())) {
foreach($eshopLink->getDepartments() as $dep) {
$depExist = $em->getRepository(Server::class)->getDepartment($dep->getDepartmentId());
print('<hr>qqw eshopLink dep: ');
\Doctrine\Common\Util\Debug::dump($dep);
print('<br>qqw eshopLink dep: ');
\Doctrine\Common\Util\Debug::dump($depExist);
if(!is_array($dep) && $eshopLink->getDepartments()->contains($dep) ) {
@$eshopLink->removeDepartment($dep);
}
if(!empty($depExist)) {
$eshopLink->addDepartment($depExist);
$em->persist($depExist);
}
}
}
$feed = $session->get('feed');
$feed->setUserId($userExist->getUserId());
/* we persist associated feed departments */
if(!empty($feed->getDepartments())) {
foreach($feed->getDepartments() as $dep) {
$depExist = $em->getRepository(Server::class)->getDepartment($dep->getDepartmentId());
if(!is_array($dep) && $feed->getDepartments()->contains($dep) ) {
@$feed->removeDepartment($dep);
}
if(!empty($depExist)) {
$feed->addDepartment($depExist);
$em->persist($depExist);
}
}
}
// we set this eshopLink as current one
$em->getRepository(EshopLink::class)->unsetCurrentEshopLink($user->getUserId());
$eshopLink->setEshopLinkCurrent(true);
/* we set this feed as current one */
$em->getRepository(Feed::class)->unsetCurrentFeed($user->getUserId());
$feed->setFeedCurrent(true);
$user->setDatabaseUser($this->databaseUser);
$user->setDatabasePassword($this->databasePassword);
/* we persist and save user (again) */
$em->persist($user);
$em->flush();
/* we persist and save eshopLink */
//$em->persist($eshopLink->getDepartments());
$em->persist($eshopLink);
$em->persist($feed);
$em->flush();
//$session->remove('eshopLink');
$session->remove('eshopLink');
$session->remove('feed');
}
/* we load logged user into session */
$session = $request->getSession();
$session->set('user', $user);
//sends email to owner
$subject = 'New User Registered - '.$session->get('label');
$from = 'info@webexciter.com';
$message = 'New User Registered on '.$session->get('label')
."\n"."Company: ".$user->getCompany()
."\n"."Email: ".$user->getEmail()
."\n"."Username: ".$user->getUserName()
."\n"."Password: ".$password
."\n"."---------------------------"
."\n"."Services: ".$servicesString
."\n"."Modules: ".$modulesString
;
//$this->sendAdminEmail($subject, $from, $message);
/*
print('<hr>we set session user: ');
\Doctrine\Common\Util\Debug::dump($session->get('user'));
*/
$this->addFlash('notice', 'New user was created.');
$this->addFlash('notice', 'Welcome '.$user->getUserName().'. You are logged in.');
return $this->redirectToRoute('homeuser');
}
else {
$this->addFlash('error', 'Both password fields must be the same.');
}
}
else {
$this->addFlash('error', 'User with this username already exists.');
}
} else {
$this->addFlash('error', 'Wrong form data.');
}
}
/* we render data */
return $this->render('newaccount.html.twig',
array('form' => $formBuilder->getForm()->createView(),
'headerData' => $this -> getPageHeader($request),
'server' => $server
)
);
}
#[Route('/logout', name: 'logout')]
public function logoutAction(Request $request) {
/* we load session data */
parent::init($request);
/* we unload logged user session */
$session = $request->getSession();
//$session->set('user', null);
$session->remove('user');
$session->remove('label');
$flashMessage = $this->translator->trans('system.user_logged_out');
$this->addFlash('notice', $flashMessage);
return $this->redirectToRoute('root');
}
#[Route('/newlang', name: 'newlang')]
public function newlangAction(Request $request) {
/* we load session data */
parent::init($request);
$em = $this->doctrine->getManager();
$session = $request->getSession();
/* setting new language */
if(!empty($request->query->get('newlang'))) {
print("<br>QQW setting new language: ".$request->query->get('newlang'));
$lang = $em->getRepository(Language::class)->getLanguageByKey($request->query->get('newlang'));
if(!empty($lang)) {
$session->set('lang', $lang);
$this->addFlash('notice', 'Language was changed to '.$lang->getLangName().'.');
}
}
/*
print("<br>QQW newlangAction: ");
\Doctrine\Common\Util\Debug::dump($session->get('lang'));
die();
*/
/*
if(!empty($request->query->get('routeName'))) {
$redirectRoute = $request->query->get('routeName');
} else {
$redirectRoute = 'root';
}
*/
if(!empty($request->query->get('routePath'))) {
$redirectPath = $request->query->get('routePath');
} else {
$redirectPath = './';
}
return $this->redirect($redirectPath);
//return $this->redirectToRoute($redirectRoute);
}
#[Route('/installModule/{moduleId}', name: 'installModule')]
public function installModuleAction(Request $request, $moduleId)
{
/* we load session data */
parent::init($request);
$em = $this->doctrine->getManager();
$session = $request->getSession();
/* we get current user */
$currentUserId = $session->get('user')->getUserId();
$user = $em->getRepository(User::class)->getUser($currentUserId);
$module = $em->getRepository(Module::class)->getModule($moduleId);
$moduleCollection = $em->getRepository(Module::class)->getModuleList();
/*
print('<br>qqw moduleCollection: ');
\Doctrine\Common\Util\Debug::dump($moduleCollection);
print('<hr>qqw userModuleCollection: ');
\Doctrine\Common\Util\Debug::dump($user->getModules());
print('<br>qqw new module: '.$module->getModuleName());
*/
//$user->addModule($module);
/*
print('<hr>qqw userModuleCollection 77: ');
\Doctrine\Common\Util\Debug::dump($user->getModules());
*/
/* we check if user has this module already */
$isModule = false;
foreach($user->getModules() as $mod) {
//print('<hr>qqw travModule '.$mod->getModuleId().': '.$mod->getModuleName());
//print('<hr>qqw currModule '.$module->getModuleId().': '.$module->getModuleName());
if($mod->getModuleId() == $module->getModuleId()) {
$isModule = true;
}
/*
print('<hr>qqw installing module: ');
\Doctrine\Common\Util\Debug::dump($module->getModuleName());
*/
}
/*
print('<hr>qqw is module: ');
\Doctrine\Common\Util\Debug::dump($isModule);
*/
if($isModule == false) {
/* we add module to user */
$user->addModule($module);
$session->get('user')->addModule($module);
//print('<hr>qqw adding module ');
//print('<hr>qqw persist user: ');
/* we persist and save user */
$em->persist($user);
//$em->persist($user->getModules());
$em->flush();
$this->addFlash('notice', 'Module was installed.');
}
/*
\Doctrine\Common\Util\Debug::dump($user->getModules());
*/
//die();
print('<hr>qqw getAction: '.$module->getAction());
//if(!empty($module->getLandingUrl())) {
//return $this->redirectToRoute($module->getLandingUrl());
//} else {
//return $this->redirectToRoute($module->getAction());
//}
return $this->redirectToRoute($module->getAction());
//return $this->redirectToRoute('homeuser');
}
#[Route('/module/{moduleId}', name: 'module')]
public function moduleAction(Request $request, $moduleId)
{
/* we load session data */
parent::init($request);
$em = $this->doctrine->getManager();
$session = $request->getSession();
$module = $em->getRepository(Module::class)->getModule($moduleId);
/* we render data */
return $this->render('module.html.php',
array('headerData' => $this -> getPageHeader($request),
'module' => $module
)
);
}
#[Route('/contact', name: 'contact')]
public function contactAction(Request $request) {
/* we load session data */
parent::init($request);
$em = $this->doctrine->getManager();
/* we render data */
return $this->render('contact.html.twig',
array('headerData' => $this -> getPageHeader($request)
)
);
}
#[Route('/aboutus', name: 'aboutus')]
public function aboutusAction(Request $request) {
/* we load session data */
parent::init($request);
$em = $this->doctrine->getManager();
/* we render data */
return $this->render('aboutus.html.twig',
array('headerData' => $this -> getPageHeader($request)
)
);
}
#[Route('/request', name: 'request')]
public function requestAction(Request $request) {
/* we load session data */
parent::init($request);
$em = $this->doctrine->getManager();
/* we prepare data for the form */
if(!empty($request->request->get('company'))) {
$company = $request->request->get('company');
} else {
$company = '';
}
if(!empty($request->request->get('email'))) {
$email = $request->request->get('email');
} else {
$email = '';
}
if(!empty($request->request->get('telephone'))) {
$telefon = $request->request->get('telephone');
} else {
$telefon = '';
}
if(!empty($request->request->get('subject'))) {
$subject = $request->request->get('subject');
} else {
$subject = '';
}
if(!empty($request->request->get('message'))) {
$message = $request->request->get('message');
} else {
$message = '';
}
/* we build register form */
$formBuilder = $this->createFormBuilder();
$formBuilder->add('company', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.company'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $company),
'label_attr' => array('class' => 'form_field_label')
));
$formBuilder->add('email', EmailType::class, array(
'required' => true,
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $email),
'label_attr' => array('class' => 'form_field_label_required'),
));
$formBuilder->add('telefon', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('user.telephone'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $telefon),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('subject', TextType::class, array(
'required' => false,
'label' => $this->translator->trans('eshop.request_subject'),
'attr' => array('class' => 'text_form', 'size' => 35, 'value' => $subject),
'label_attr' => array('class' => 'form_field_label'),
));
$formBuilder->add('message', TextareaType::class, array(
'required' => false,
'label' => $this->translator->trans('eshop.request_message'),
'attr' => array('class' => 'textarea_form', 'cols' => 70, 'rows' => 10, 'value' => $message),
'label_attr' => array('class' => 'form_textarea_label'),
));
$formBuilder->add('save', SubmitType::class, array('label' => $this->translator->trans('eshop.request_send'),
'attr' => array('class' => 'butt_big')));
$form = $formBuilder->getForm();
$form->handleRequest($request);
if ($request->getMethod() == 'POST') {
//$form->bindRequest($request);
if ($form->isValid()) {
$subject = $form['subject']->getData();
$message = "\n message: ".$form['message']->getData();
$from = $form['email']->getData();
$message .= "\n company: ".$form['company']->getData();
$message .= "\n email: ".$form['email']->getData();
$message .= "\n tel: ".$form['telefon']->getData();
$body = $message;
$this->sendAdminEmail($subject, $from, $message);
//print('<br>Sending email data...');
}
}
/* we render data */
return $this->render('request.html.twig',
array('headerData' => $this -> getPageHeader($request),
'form' => $formBuilder->getForm()->createView()
)
);
}
public function adminMenu(Request $request)
{
$menuItems = array(0 => array('link' => 'homeuser', 'langKey' => 'user.admin', 'routeName' => 'homeuser'),
1 => array('link' => 'eshopAdmin', 'langKey' => 'eshop.admin', 'routeName' => 'eshopAdmin'),
2 => array('link' => 'orderlist', 'langKey' => 'eshop.orders', 'routeName' => 'orderList'),
3 => array('link' => 'productedit', 'langKey' => 'eshop.products', 'routeName' => 'productListEdit'),
4 => array('link' => 'productnew', 'langKey' => 'eshop.new_product', 'routeName' => 'productNew'),
5 => array('link' => 'categories', 'langKey' => 'eshop.categories', 'routeName' => 'categories'),
6 => array('link' => 'categorynew', 'langKey' => 'eshop.new_category', 'routeName' => 'categoryNew'),
7 => array('link' => 'contacts', 'langKey' => 'knowledgebase.contacts', 'routeName' => 'contacts'),
8 => array('link' => 'eshopnew', 'langKey' => 'eshop.new_eshop', 'routeName' => 'eshopNew'),
9 => array('link' => 'eshopConfig', 'langKey' => 'eshop.config', 'routeName' => 'eshopConfig'),
);
return $menuItems;
}
}