src/ApplicationBundle/Controller/SystemAdminController.php line 27

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Controller;
  3. use ApplicationBundle\Constants\EmailConstant;
  4. use ApplicationBundle\Constants\GeneralConstant;
  5. use ApplicationBundle\Constants\ModuleConstant;
  6. use ApplicationBundle\Entity\ApprovalSettings;
  7. use ApplicationBundle\Entity\EmailSenderSettings;
  8. use ApplicationBundle\Entity\SysDepartmentPosition;
  9. use ApplicationBundle\Entity\SysDeptPositionDefaultModule;
  10. use ApplicationBundle\Interfaces\SystemInterface;
  11. use ApplicationBundle\Modules\Authentication\Constants\UserConstants;
  12. use ApplicationBundle\Modules\Api\Constants\ApiConstants;
  13. use ApplicationBundle\Modules\Inventory\Inventory;
  14. use ApplicationBundle\Modules\Production\ProductionM;
  15. use ApplicationBundle\Modules\System\DeleteDocument;
  16. use ApplicationBundle\Modules\System\System;
  17. use ApplicationBundle\Modules\User\Users;
  18. use Symfony\Component\HttpFoundation\JsonResponse;
  19. use Symfony\Component\HttpFoundation\Request;
  20. class SystemAdminController extends GenericController implements SystemInterface
  21. {
  22.     public function indexAction(Request $request)
  23.     {
  24.         // ?shell=cp renders the same (cp-themed) body inside the Company
  25.         // Administration cp-shell so the sidebar persists; default = system-admin chrome.
  26.         $tpl = ($request->query->get('shell') === 'cp')
  27.             ? '@System/pages/view_admin_dashboard_cp.html.twig'
  28.             '@System/pages/dashboard.html.twig';
  29.         return $this->render($tpl, array(
  30.             'page_title' => 'Command Center',
  31.         ));
  32.     }
  33.     public function addPositionAction(Request $request)
  34.     {
  35.         $em $this->getDoctrine()->getManager();
  36.         if ($request->isMethod('POST')) {
  37.             $find_it $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartmentPosition')->findOneBy(array(
  38.                 'status' => GeneralConstant::ACTIVE,
  39.                 'positionName' => $request->request->get('positionName'),
  40.                 'departmentId' => $request->request->get('departmentId')
  41.             ));
  42.             if ($find_it) {
  43.                 //nothing
  44.             } else {
  45.                 $new = new SysDepartmentPosition();
  46.                 $parent_position $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartmentPosition')->findOneBy(array(
  47. //                    'status'=>GeneralConstant::ACTIVE,
  48. //                    'name'=>$request->request->get('positionName')
  49.                     'positionId' => $request->request->get('parentPositionId')
  50.                 ));
  51.                 $new->setDepartmentId($request->request->get('departmentId'));
  52.                 $new->setPositionName($request->request->get('positionName'));
  53.                 $new->setLevel(($parent_position) ? $parent_position->getLevel() * 0);
  54.                 $new->setParentPositionId($request->request->get('parentPositionId'));
  55. //                $new->set
  56.                 $new->setStatus(GeneralConstant::ACTIVE);
  57.                 $em->persist($new);
  58.                 $em->flush();
  59.             }
  60.             // cp-shell org page posts redirectTo so the user returns to the shell.
  61.             if ($request->request->get('redirectTo')) {
  62.                 return $this->redirect($request->request->get('redirectTo'));
  63.             }
  64.         }
  65.         $positions $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartmentPosition')->findBy(array(
  66.             'status' => GeneralConstant::ACTIVE,
  67.         ));
  68.         $pos_array = [];
  69.         $pos_obj = [];
  70.         $pos_obj_by_dept = [];
  71.         foreach ($positions as $entry) {
  72.             $dt = array(
  73.                 'id' => $entry->getPositionId(),
  74.                 'name' => $entry->getPositionName(),
  75.                 'deptId' => $entry->getDepartmentId(),
  76.             );
  77.             $pos_array[] = $dt;
  78.             $pos_obj[$entry->getPositionId()] = $dt;
  79.             $pos_obj_by_dept[$entry->getDepartmentId()][] = $dt;
  80.         }
  81.         return $this->render('@System/pages/settings/add_position.html.twig',
  82.             array(
  83.                 'page_title' => 'Dashboard',
  84.                 'positions' => $positions,
  85.                 'posArray' => $pos_array,
  86.                 'posObj' => $pos_obj,
  87.                 'posObjByDept' => $pos_obj_by_dept,
  88.                 'departments' => $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartment')->findBy(array(
  89.                     'status' => GeneralConstant::ACTIVE,
  90.                 ))
  91.             )
  92.         );
  93.     }
  94.     public function ApprovalSettingsAction(Request $request)
  95.     {
  96.         $id 0;
  97.         $cc_id '';
  98.         $cc_name '';
  99.         if ($request->isMethod('POST')) {
  100.             $em $this->getDoctrine()->getManager();
  101.             $em->getConnection()->query('START TRANSACTION;SET FOREIGN_KEY_CHECKS=0; TRUNCATE approval_setting; SET FOREIGN_KEY_CHECKS=1; COMMIT;');
  102.             foreach ($request->request->get('settingsId', []) as $key => $value) {
  103.                 //first check if it exists so we can update
  104.                 $user_id_list = [];
  105.                 $user_id_list $request->request->get('userId_' $request->request->get('rowId')[$key], []);
  106.                 $new = new ApprovalSettings();
  107.                 $new->setEntity($request->request->get('entity')[$key]);
  108.                 $new->setEntitySub($request->request->get('subCatId')[$key]);
  109.                 $new->setPositionId($request->request->get('positionId')[$key]);
  110.                 $new->setSequence($request->request->get('sequence')[$key]);
  111.                 $new->setUserAssignType($request->request->get('userAssignType')[$key]);
  112.                 $new->setUserId(implode(','$user_id_list));
  113.                 $new->setRoleType($request->request->get('roleType')[$key]);
  114.                 $new->setRequired($request->request->get('required')[$key]);
  115.                 $new->setSkipPrintFlag($request->request->get('skipPrintFlag')[$key]);
  116.                 $new->setSuccession($request->request->get('succession')[$key]);
  117.                 $new->setSuccessionTimeout($request->request->get('successionTimeout')[$key]);
  118.                 // Conditional approval layers (TODO-C) — optional; null = always applies.
  119.                 $condField $request->request->get('conditionField', []);
  120.                 $condOp    $request->request->get('conditionOp', []);
  121.                 $condValue $request->request->get('conditionValue', []);
  122.                 $new->setConditionField(isset($condField[$key]) && $condField[$key] !== '' $condField[$key] : null);
  123.                 $new->setConditionOp(isset($condOp[$key]) && $condOp[$key] !== '' $condOp[$key] : null);
  124.                 $new->setConditionValue(isset($condValue[$key]) && $condValue[$key] !== '' $condValue[$key] : null);
  125.                 $em->persist($new);
  126.             }
  127.             $em->flush();
  128.         }
  129.         $data $this->getDoctrine()
  130.             ->getRepository('ApplicationBundle\\Entity\\ApprovalSettings')
  131.             ->findAll(
  132.                 [], array(
  133.                     'entity' => 'ASC',
  134.                     'sequence' => 'ASC',
  135.                 )
  136.             );
  137.         $Entity_list GeneralConstant::$Entity_list_details;
  138.         $positionAssignType GeneralConstant::$positionAssignType;
  139.         $approvalAction GeneralConstant::$approvalAction;
  140.         $approvalRequired GeneralConstant::$approvalRequired;
  141. //        $approvalRole=GeneralConstant::$approvalRole;
  142.         $approvalRole GeneralConstant::$approvalRole;
  143. //        $approvalRoles=GeneralConstant::$approvalRoleForPrint;
  144.         //now add additional roles form dbase
  145.         $addRoles $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\ApprovalRole')
  146.             ->findBy(
  147.                 array(//                    'id' => $v->getSigId()
  148.                 )
  149.             );
  150.         foreach ($addRoles as $addRole) {
  151.             $approvalRole[$addRole->getIndexId()] = $addRole->getName();
  152.         }
  153.         $userList $this->get('user_module')->showUserList();
  154.         $Positions $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartmentPosition')->findBy(array(
  155.             'status' => GeneralConstant::ACTIVE,
  156.         ));
  157.         $positionList = [];
  158.         $Departments $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartment')->findBy(array(
  159.             'status' => GeneralConstant::ACTIVE,
  160.         ));
  161.         $depts = [];
  162.         foreach ($Departments as $entry) {
  163.             $depts[$entry->getDepartmentId()] = array(
  164.                 'id' => $entry->getDepartmentId(),
  165.                 'name' => $entry->getDepartmentName(),
  166.             );
  167.         }
  168.         return $this->render('@System/pages/settings/approval_settings.html.twig',
  169.             array(
  170.                 'page_title' => 'Settings',
  171.                 'data' => $data,
  172.                 'entity_list' => $Entity_list,
  173.                 'positionAssignType' => $positionAssignType,
  174.                 'approvalAction' => $approvalAction,
  175.                 'approvalRequired' => $approvalRequired,
  176.                 'approvalRole' => $approvalRole,
  177.                 'userList' => $userList,
  178.                 'positions' => $Positions,
  179.                 'departments' => $depts,
  180.             )
  181.         );
  182.     }
  183.     public function ModuleAccessSettingsAction(Request $request$id 0)
  184.     {
  185.         $id 0;
  186.         $cc_id '';
  187.         $cc_name '';
  188. //        $cur_pos=0;
  189.         $cur_pos $id;
  190.         if ($request->isMethod('POST')) {
  191.             $em $this->getDoctrine()->getManager();
  192. //            $em->getConnection()->query('START TRANSACTION;SET FOREIGN_KEY_CHECKS=0; TRUNCATE approval_setting; SET FOREIGN_KEY_CHECKS=1; COMMIT;');
  193.             $mod_data = [];
  194. //            foreach ($request->request->get('modules') as $d) {
  195. //                $mod_data[] = $d * 1;
  196. //            }
  197.             $modules $request->request->get('modules');
  198.             if (is_array($modules)) {
  199.                 foreach ($modules as $d) {
  200.                     $mod_data[] = $d 1;
  201.                 }
  202.             }
  203.             $already_exists $this->getDoctrine()
  204.                 ->getRepository('ApplicationBundle\\Entity\\SysDeptPositionDefaultModule')
  205.                 ->findOneBy(
  206.                     array(
  207.                         'positionId' => $request->request->get('position')
  208.                     )
  209.                 );
  210.             if ($already_exists) {
  211.                 $already_exists->setModuleIds(json_encode($mod_data));
  212.             } else {
  213.                 $new = new SysDeptPositionDefaultModule();
  214.                 $new->setModuleIds(json_encode($mod_data));
  215.                 $new->setPositionId($request->request->get('position'));
  216.                 $new->setStatus(GeneralConstant::ACTIVE);
  217. //                $new->set(GeneralConstant::ACTIVE);
  218.                 $em->persist($new);
  219.             }
  220.             $em->flush();
  221.         }
  222.         $cur_pos_modules $this->getDoctrine()
  223.             ->getRepository('ApplicationBundle\\Entity\\SysDeptPositionDefaultModule')
  224.             ->findAll();
  225.         $modules $this->getDoctrine()
  226.             ->getRepository('ApplicationBundle\\Entity\\SysModule')
  227.             ->findBy(
  228.                 array(//                'level'=>[1,2]
  229.                 )
  230.             );
  231.         $module_data = [];
  232.         $module_data_by_parent_id = [];
  233. //        $module_parent_id_data=[];
  234.         $module_data_array = [];
  235.         $position_modules = [];
  236.         $position_modules_by_position = [];
  237.         $position_modules_array = [];
  238.         foreach ($modules as $entry) {
  239.             $dt = array(
  240.                 'id' => $entry->getModuleId(),
  241.                 'name' => $entry->getModuleName(),
  242.                 'parentId' => $entry->getParentId()
  243.             );
  244.             $module_data[$entry->getModuleId()] = $dt;
  245.             $module_data_by_parent_id[$entry->getParentId()] = $dt;
  246.             $module_data_array[] = $dt;
  247.         }
  248.         foreach ($cur_pos_modules as $entry) {
  249.             $dt = array(
  250.                 'id' => $entry->getId(),
  251.                 'positionId' => $entry->getPositionId(),
  252. //                'dept'=>$entry->getDepartmentId(),
  253.                 'data' => json_decode($entry->getModuleIds(), true)
  254.             );
  255.             $position_modules[$entry->getId()] = $dt;
  256.             $position_modules_by_position[$entry->getPositionId()] = $dt;
  257.             $position_modules_array[] = $dt;
  258.         }
  259. //        $Entity_list=GeneralConstant::$Entity_list_details;
  260. //        $positionAssignType=GeneralConstant::$positionAssignType;
  261. //        $approvalAction=GeneralConstant::$approvalAction;
  262. //        $approvalRequired=GeneralConstant::$approvalRequired;
  263. //        $approvalRole=GeneralConstant::$approvalRole;
  264. //        $userList=$this->get('user_module')->showUserList();
  265.         $Positions $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartmentPosition')->findBy(array(
  266.             'status' => GeneralConstant::ACTIVE,
  267.         ));
  268.         $Departments $this->getDoctrine()->getRepository('ApplicationBundle\\Entity\\SysDepartment')->findBy(array(
  269.             'status' => GeneralConstant::ACTIVE,
  270.         ));
  271.         $depts = [];
  272.         foreach ($Departments as $entry) {
  273.             $depts[$entry->getDepartmentId()] = array(
  274.                 'id' => $entry->getDepartmentId(),
  275.                 'name' => $entry->getDepartmentName(),
  276.             );
  277.         }
  278.         return $this->render('@System/pages/settings/module_access.html.twig',
  279.             array(
  280.                 'page_title' => 'Settings',
  281.                 'positions' => $Positions,
  282.                 'departments' => $depts,
  283.                 'module_data' => $module_data,
  284.                 'parent_modules' => ModuleConstant::$parentModuleList,
  285.                 'module_data_by_parent_id' => $module_data_by_parent_id,
  286.                 'module_data_array' => $module_data_array,
  287.                 'position_modules' => $position_modules,
  288.                 'position_modules_by_position' => $position_modules_by_position,
  289.                 'position_modules_array' => $position_modules_array
  290.             )
  291.         );
  292.     }
  293.     public function UserListAction(Request $request)
  294.     {
  295.         $systemType $this->container->hasParameter('system_type') ? $this->container->getParameter('system_type') : '_ERP_';
  296.         $post $request;
  297.         $globalIdsByAppIdAndUser = [];
  298.         if ($request->isMethod('POST')) {
  299.             $message $this->get('user_module')->addNewUser(
  300.                 $request->request->get('name'),
  301.                 $request->request->get('email'),
  302.                 $request->request->has('username') ? $request->request->get('username') : $request->request->get('email'),
  303.                 $request->request->get('password'),
  304.                 $request->request->get('position'),
  305.                 $this->getLoggedUserLoginId($request),
  306.                 $request->request->get('company'),
  307.                 $request->request->get('userType'),
  308.                 $request->request->get('companyIdList'),
  309.                 $request->request->get('branchIdList'),
  310.                 $request->request->get('supervisor'),
  311.                 $request->request->get('defaultRoute'),
  312.                 $request->request->has('allModuleAccessFlag') ? 0
  313.             );
  314.             $companyData $message[2];
  315.             if ($message[0] == 'success') {
  316.                 if ($systemType == '_CENTRAL_') {
  317.                 } else {
  318.                     $em_goc $this->getDoctrine()->getManager('company_group');
  319.                     $em_goc->getConnection()->connect();
  320.                     $connected $em_goc->getConnection()->isConnected();
  321.                     $gocDataList = [];
  322.                     $gocDataListByAppId = [];
  323.                     $retDataDebug = array();
  324.                     $appIds $message[2]->getAppId();
  325.                     $userIds $message[3]->getUserId();
  326.                     if ($connected) {
  327.                         $findByQuery = array(
  328.                             'active' => 1
  329.                         );
  330.                         if ($appIds !== '_UNSET_')
  331.                             $findByQuery['appId'] = $appIds;
  332.                         $gocList $this->getDoctrine()->getManager('company_group')
  333.                             ->getRepository("CompanyGroupBundle\\Entity\\CompanyGroup")
  334.                             ->findBy($findByQuery);
  335.                         foreach ($gocList as $entry) {
  336.                             $d = array(
  337.                                 'name' => $entry->getName(),
  338.                                 'id' => $entry->getId(),
  339.                                 'image' => $entry->getImage(),
  340.                                 'companyGroupHash' => $entry->getCompanyGroupHash(),
  341.                                 'dbName' => $entry->getDbName(),
  342.                                 'dbUser' => $entry->getDbUser(),
  343.                                 'dbPass' => $entry->getDbPass(),
  344.                                 'dbHost' => $entry->getDbHost(),
  345.                                 'appId' => $entry->getAppId(),
  346.                                 'companyRemaining' => $entry->getCompanyRemaining(),
  347.                                 'companyAllowed' => $entry->getCompanyAllowed(),
  348.                             );
  349.                             $gocDataList[$entry->getId()] = $d;
  350.                             $gocDataListByAppId[$entry->getAppId()] = $d;
  351.                         }
  352.                         $debugCount 0;
  353.                         foreach ($gocDataList as $gocId => $entry) {
  354. //                    if($debugCount>0)
  355. //                        continue;
  356.                             $skipSend 1;
  357.                             $connector $this->container->get('application_connector');
  358.                             $connector->resetConnection(
  359.                                 'default',
  360.                                 $gocDataList[$gocId]['dbName'],
  361.                                 $gocDataList[$gocId]['dbUser'],
  362.                                 $gocDataList[$gocId]['dbPass'],
  363.                                 $gocDataList[$gocId]['dbHost'],
  364.                                 $reset true);
  365.                             $em $this->getDoctrine()->getManager();
  366.                             if ($userIds !== '_UNSET_')
  367.                                 $users $this->getDoctrine()
  368.                                     ->getRepository('ApplicationBundle\\Entity\\SysUser')
  369.                                     ->findBy(
  370.                                         array(
  371.                                             'userId' => $userIds
  372.                                         )
  373.                                     );
  374.                             else
  375.                                 $users $this->getDoctrine()
  376.                                     ->getRepository('ApplicationBundle\\Entity\\SysUser')
  377.                                     ->findBy(
  378.                                         array()
  379.                                     );
  380.                             $output '';
  381.                             $userData = array();
  382.                             $userFiles = array();
  383.                             foreach ($users as $user) {
  384.                                 $file $this->container->getParameter('kernel.root_dir') . '/../web/' $user->getImage(); //<-- Path could be relative
  385. //                            $output=$file;
  386.                                 if ($user->getImage() != '' && $user->getImage() != null && file_exists($file)) {
  387. //                        $file = new \CURLFile($this->container->getParameter('kernel.root_dir') . '/../web/uploads/CompanyImage/' . $company->getImage()); //<-- Path could be relative
  388.                                     $mime mime_content_type($file);
  389.                                     $info pathinfo($file);
  390.                                     $name $info['basename'];
  391.                                     if (strpos($mime'image') !== false) {
  392.                                         $output = new \CURLFile($file$mime$name);
  393.                                     }
  394.                                     $skipSend 0;
  395.                                     $userFiles['file_' $user->getUserAppId() . '_' $user->getUserId()] = $output;
  396.                                 } else {
  397. //                                    unlink($this->container->getParameter('kernel.root_dir') . '/../web'. $centralUser->getImage());
  398.                                     $user->setImage(null);
  399.                                     $userFiles['file_' $user->getUserAppId() . '_' $user->getUserId()] = 'pika';
  400.                                     $em->flush();
  401.                                 }
  402.                                 $getters array_filter(get_class_methods($user), function ($method) {
  403.                                     return 'get' === substr($method03);
  404.                                 });
  405.                                 $userDataSingle = array(//                                'file'=>$output
  406.                                 );
  407.                                 foreach ($getters as $getter) {
  408.                                     if ($getter == 'getCreatedAt' || $getter == 'getUpdatedAt' || $getter == 'getImage')
  409.                                         continue;
  410. //                                if(is_string($user->{$getter}())|| is_numeric($user->{$getter}()))
  411. //                                {
  412. //                                    $userDataSingle[$getter]= $user->{$getter}();
  413. //                                }
  414.                                     if ($user->{$getter}() instanceof \DateTime) {
  415.                                         $ggtd $user->{$getter}();
  416.                                         $userDataSingle[$getter] = $ggtd->format('Y-m-d');
  417.                                     } else
  418.                                         $userDataSingle[$getter] = $user->{$getter}();
  419.                                 }
  420.                                 $userData[] = $userDataSingle;
  421.                             }
  422.                             $retDataDebug[$debugCount] = array(
  423.                                 'skipSend' => $skipSend
  424.                             );
  425. //                    if ($skipSend == 0)
  426.                             {
  427.                                 $urlToCall GeneralConstant::HONEYBEE_CENTRAL_SERVER '/SyncUserToCentralUser';
  428.                                 $userFiles['userData'] = json_encode($userData);
  429.                                 $curl curl_init();
  430.                                 curl_setopt_array($curl, array(
  431.                                     CURLOPT_RETURNTRANSFER => 1,
  432.                                     CURLOPT_POST => 1,
  433.                                     CURLOPT_URL => $urlToCall,
  434.                                     CURLOPT_CONNECTTIMEOUT => 10,
  435.                                     CURLOPT_SSL_VERIFYPEER => false,
  436.                                     CURLOPT_SSL_VERIFYHOST => false,
  437. //                            CURLOPT_SAFE_UPLOAD => false,
  438.                                     CURLOPT_HTTPHEADER => array(//                                "Accept: multipart/form-data",
  439.                                     ),
  440.                                     //                        CURLOPT_USERAGENT => 'InnoPM',
  441. //                            CURLOPT_POSTFIELDS => array(
  442. //                                'userData'=>json_encode($userData),
  443. //                                'userFiles'=>$userFiles
  444. //                            ),
  445.                                     CURLOPT_POSTFIELDS => $userFiles
  446.                                 ));
  447.                                 $retData curl_exec($curl);
  448.                                 $errData curl_error($curl);
  449.                                 curl_close($curl);
  450.                                 $retDataObj json_decode($retDatatrue);
  451.                                 $retDataDebug[$debugCount] = $retDataObj;
  452.                                 if (isset($retDataObj['globalIdsData']))
  453.                                     foreach ($retDataObj['globalIdsData'] as $app_id => $usrList) {
  454.                                         $connector $this->container->get('application_connector');
  455.                                         $connector->resetConnection(
  456.                                             'default',
  457.                                             $gocDataListByAppId[$app_id]['dbName'],
  458.                                             $gocDataListByAppId[$app_id]['dbUser'],
  459.                                             $gocDataListByAppId[$app_id]['dbPass'],
  460.                                             $gocDataListByAppId[$app_id]['dbHost'],
  461.                                             $reset true);
  462.                                         $em $this->getDoctrine()->getManager();
  463.                                         foreach ($usrList as $sys_id => $globaldata) {
  464.                                             $user $this->getDoctrine()
  465.                                                 ->getRepository('ApplicationBundle\\Entity\\SysUser')
  466.                                                 ->findOneBy(
  467.                                                     array(
  468.                                                         'userId' => $sys_id
  469.                                                     )
  470.                                                 );
  471.                                             if ($user) {
  472.                                                 $user->setGlobalId($globaldata['gid']);
  473.                                                 $em->flush();
  474.                                             }
  475.                                         }
  476.                                     }
  477.                             }
  478.                             $debugCount++;
  479.                         }
  480.                     }
  481. //                    return new JsonResponse($retDataDebug);
  482.                 }
  483.             }
  484.             if ($message[0] == 'success' && GeneralConstant::EMAIL_ENABLED == 1) {
  485.                 $bodyHtml '';
  486.                 $bodyTemplate '@Application/email/user/registration.html.twig';
  487.                 $bodyData = array(
  488.                     'name' => $request->request->get('name'),
  489.                     'companyData' => $companyData,
  490.                     'userName' => $request->request->get('username'),
  491.                     'password' => $request->request->get('password'),
  492.                 );
  493.                 $attachments = [];
  494. //                    $upl_dir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads/temp/' . 'ledger' . '.pdf'
  495.                 $new_mail $this->get('mail_module');
  496.                 $new_mail->sendMyMail(array(
  497. //                  'senderHash' => '_USER_MANAGEMENT_',
  498.                     'senderHash' => '_CUSTOM_',
  499.                     'forwardToMailAddress' => $request->request->get('email'),
  500.                     'subject' => 'User Registration on HoneyBee Ecosystem under Company ' $companyData->getName(),
  501.                     'fileName' => '',
  502.                     'attachments' => $attachments,
  503.                     'toAddress' => $request->request->get('email'),
  504.                     'fromAddress' => 'registration@ourhoneybee.eu',
  505.                     'userName' => 'registration@ourhoneybee.eu',
  506.                     'password' => \ApplicationBundle\Helper\MailerConfig::buddybeePassword(),
  507.                     'smtpServer' => \ApplicationBundle\Helper\MailerConfig::host(),
  508.                     'smtpPort' => \ApplicationBundle\Helper\MailerConfig::port(),
  509.                     'encryptionMethod' => 'ssl',
  510.                     'mailTemplate' => $bodyTemplate,
  511.                     'templateData' => $bodyData,
  512.                     'embedCompanyImage' => 1,
  513.                     'companyId' => $request->request->get('company'),
  514.                     'companyImagePath' => $companyData->getImage()
  515.                 ));
  516. //                $emailmessage = (new \Swift_Message('Registration to Entity'))
  517. //                    ->setFrom('registration@entity.innobd.com')
  518. //                    ->setTo($request->request->get('email'))
  519. //                    ->setBody(
  520. //                        $this->renderView(
  521. //                            'ApplicationBundle:email/user:registration.html.twig',
  522. //                            array('name' => $request->request->get('name'),
  523. //                                'companyData' => $companyData,
  524. //                                'userName' => $request->request->get('email'),
  525. //                                'password' => $request->request->get('password'),
  526. //                            )
  527. //                        ),
  528. //                        'text/html'
  529. //                    );
  530. //                /*
  531. //                 * If you also want to include a plaintext version of the message
  532. //                ->addPart(
  533. //                    $this->renderView(
  534. //                        'Emails/registration.txt.twig',
  535. //                        array('name' => $name)
  536. //                    ),
  537. //                    'text/plain'
  538. //                )
  539. //                */
  540. ////            ;
  541. //                $this->get('mailer')->send($emailmessage);
  542.             }
  543.             $this->addFlash(
  544.                 $message[0],
  545.                 $message[1]
  546.             );
  547.             // cp-shell Users page posts redirectTo so creation returns to the shell.
  548.             if ($request->request->get('redirectTo')) {
  549.                 return $this->redirect($request->request->get('redirectTo'));
  550.             }
  551.         }
  552.         // Hide explicitly-retired modules (sys_module.status = 0) from the permission grid
  553.         // so users can't be granted access to outdated/old pages. status IS NULL or non-zero
  554.         // stays visible (tenants that never set the flag are unaffected).
  555.         $modules $this->getDoctrine()
  556.             ->getRepository('ApplicationBundle\\Entity\\SysModule')
  557.             ->createQueryBuilder('m')
  558.             ->where('m.level = 1')
  559.             ->andWhere('(m.status IS NULL OR m.status <> 0)')
  560.             ->getQuery()
  561.             ->getResult();
  562.         $module_data = [];
  563.         $module_data_by_parent_id = [];
  564.         $module_data_array = [];
  565.         $position_modules = [];
  566.         $position_modules_by_position = [];
  567.         $position_modules_array = [];
  568.         foreach ($modules as $entry) {
  569.             $dt = array(
  570.                 'id' => $entry->getModuleId(),
  571.                 'name' => $entry->getModuleName(),
  572.                 'route' => $entry->getModuleRoute(),
  573.                 'parentId' => $entry->getParentId()
  574.             );
  575.             $module_data[$entry->getModuleId()] = $dt;
  576.             $module_data_by_parent_id[$entry->getParentId()] = $dt;
  577.             $module_data_array[] = $dt;
  578.         }
  579.         $userList $this->get('user_module')->showUserListDesc();
  580.         return $this->render('@System/pages/user_list.html.twig',
  581.             array(
  582.                 'page_title' => 'Users',
  583.                 'user_list' => $userList,
  584.                 'module_data_array' => $module_data_array
  585.             )
  586.         );
  587.     }
  588.     public function DocumentManagementAction(Request $request$id)
  589.     {
  590.         $em $this->getDoctrine()->getManager();
  591.         $errorNote "";
  592.         if ($request->isMethod('POST')) {
  593.             $options = array(
  594.                 'notification_enabled' => $this->container->getParameter('notification_enabled'),
  595.                 'notification_server' => $this->container->getParameter('notification_server'),
  596. //                'appId'=>$request->getSession()->get(UserConstants::USER_APP_ID),
  597. //                'url'=>$this->generateUrl(
  598. //                    GeneralConstant::$Entity_list_details[$request->request->get('approvalEntity')]['entity_view_route_path_name']
  599. //                )
  600.             );
  601.             $notification_enabled 0;
  602.             $notification_server '';
  603.             if (!empty($options)) {
  604.                 $notification_enabled $options['notification_enabled'];
  605.                 $notification_server $options['notification_server'];
  606. //            $appId =$options['appId'];
  607. //            $url = $options['url'];
  608.             }
  609.             if ($request->request->get('entityId') != '' && $request->request->get('docId') != '')
  610.                 $doc $em->getRepository('ApplicationBundle\\Entity\\' GeneralConstant::$Entity_list[$request->request->get('entityId')])
  611.                     ->findOneBy(
  612.                         array(
  613.                             GeneralConstant::$Entity_id_field_list[$request->request->get('entityId')] => $request->request->get('docId'),
  614.                         )
  615.                     );
  616.             if ($request->request->get('actionId') != '') {
  617.                 $action $request->request->get('actionId'); //1:lock, 2:disable, 3:enable edit 4:enable delete 5:remove
  618.                 if ($action == 1) {
  619.                     $doc->setLockFlag(1);
  620.                     $doc->setEditFlag(0);
  621.                     $doc->setDeleteFlag(0);
  622. //                    $doc->setDisabledFlag(1);
  623.                 }
  624.                 if ($action == 2) {
  625.                     $doc->setLockFlag(1);
  626.                     $doc->setEditFlag(0);
  627.                     $doc->setDeleteFlag(0);
  628.                     $doc->setDisabledFlag(1);
  629.                 }
  630.                 if ($action == 3) {
  631.                     $all_seq_list $em->getRepository('ApplicationBundle\\Entity\\Approval')
  632.                         ->findBy(
  633.                             array(
  634.                                 'entity' => $request->request->get('entityId'),
  635.                                 'entityId' => $request->request->get('docId'),
  636. //                        'sequence' => $dt->getSequence()
  637.                             )
  638.                         );
  639.                     foreach ($all_seq_list as $useless_data) {
  640.                         //we will remove all arppovals and pendings
  641. //                        if ($useless_data->getSequence() > $dt->getSequence())
  642.                         {
  643.                             $em->remove($useless_data);
  644.                             $em->flush();
  645.                         }
  646.                     }
  647.                     //now take revert action
  648.                     $revert_doc System::takeRevertForEditActions($em$request->request->get('entityId'), $request->request->get('docId'));
  649. //                    $doc->setLockFlag(0);
  650. //                    $doc->setEditFlag(1);
  651. //                    $doc->setDeleteFlag(0);
  652. //                    $doc->setDisabledFlag(1);
  653.                 }
  654.                 if ($action == 4) {
  655.                     $doc->setLockFlag(0);
  656. //                    $doc->setEditFlag(0);
  657.                     $doc->setDeleteFlag(1);
  658. //                    $doc->setDisabledFlag(1);
  659.                 }
  660.                 if ($action == 5) {
  661.                     $funcname GeneralConstant::$Entity_list[$request->request->get('entityId')];
  662.                     $deleteAction DeleteDocument::$funcname($em$request->request->get('docId'));
  663.                     if ($deleteAction == false)
  664.                         $errorNote "Sorry , Could not Delete The Document. Possibly Another Dependent Document Exists";
  665.                 }
  666.             }
  667.             $em->flush();
  668.             if ($request->request->has('returnJson')) {
  669.                 return new JsonResponse(array(
  670.                     'success' => true,
  671.                 ));
  672.             } else {
  673.                 $this->addFlash(
  674.                     'success',
  675.                     'New Document Created'
  676.                 );
  677.             }
  678.         }
  679.         return $this->render('@System/pages/settings/document_management.html.twig',
  680.             array(
  681.                 'page_header' => 'Document Management',
  682.                 'page_title' => 'Doc Management',
  683.                 'page_header_sub' => 'Settings',
  684.                 'errorNote' => $errorNote,
  685.                 'entityList' => GeneralConstant::$Entity_list_details,
  686.             ));
  687.     }
  688.     public function DocListByEntityAction(Request $request$id 0)
  689.     {
  690.         $em $this->getDoctrine()->getManager();
  691.         $data = [];
  692.         $data_array = [];
  693.         if ($request->isMethod('POST')) {
  694.             $doc $em->getRepository('ApplicationBundle\\Entity\\' GeneralConstant::$Entity_list[$request->request->get('entityId')])
  695.                 ->findBy(
  696.                     array(//                        GeneralConstant::$Entity_id_field_list[$entity] => $entity_id,
  697.                     )
  698.                 );
  699.             if (isset(GeneralConstant::$Entity_list_details[$request->request->get('entityId')]['entity_print_route_path_name']))
  700.                 $url $this->generateUrl(
  701.                     GeneralConstant::$Entity_list_details[$request->request->get('entityId')]['entity_print_route_path_name']
  702.                 );
  703.             else
  704.                 $url $this->generateUrl(
  705.                     GeneralConstant::$Entity_list_details[$request->request->get('entityId')]['entity_view_route_path_name']
  706.                 );
  707.             $getIdfunc GeneralConstant::$Entity_id_get_method_list[$request->request->get('entityId')];
  708.             foreach ($doc as $entry//doing by doc hash for now. will change to id later i guess
  709.             {
  710.                 $dt = array(
  711. //                    'id'=>$data->get
  712.                     'id' => $entry->$getIdfunc(),
  713.                     'name' => $entry->getDocumentHash(),
  714. //                'test'=>$entry->get('transactionId'),
  715.                     'view_link' => $url "/" $entry->$getIdfunc()
  716.                 );
  717.                 $data_array[] = $dt;
  718.                 $data[$entry->$getIdfunc()] = $dt;
  719.             }
  720.             if (!empty($doc))
  721.                 return new JsonResponse(array("success" => true'dataList' => $data_array'dataObj' => $data));
  722.             return new JsonResponse(array("success" => false));
  723.         }
  724.         return new JsonResponse(array("success" => false));
  725.     }
  726.     public function CompanyListAction(Request $request)
  727.     {
  728.         $companies $this->getDoctrine()
  729.             ->getRepository('ApplicationBundle\\Entity\\Company')
  730.             ->findBy(
  731.                 array(
  732.                     'active' => GeneralConstant::ACTIVE
  733.                 ));
  734.         return $this->render('@System/pages/company_list.html.twig',
  735.             array(
  736.                 'page_header' => 'Company List',
  737.                 'page_title' => 'Company List',
  738. //                'page_header_sub'=>'Edit',
  739.                 'companies' => $companies
  740.             ));
  741.     }
  742.     public function EmailSenderSettingsAction(Request $request$id)
  743.     {
  744. //        $employee= new Employee();
  745.         $companyId $id;
  746.         $senderSettingsData = [];
  747.         $senderVarieties EmailConstant::$EmailSenderVarieties;
  748.         $em $this->getDoctrine()->getManager();
  749.         if ($request->query->has('returnDataByCompany')) {
  750.             $companyId $request->query->get('companyId');
  751.             $senderSettingsDataQry $em->getRepository('ApplicationBundle\\Entity\\EmailSenderSettings')->findBy(
  752.                 array(
  753.                     'CompanyId' => $companyId,
  754. //                    'valid'=>1
  755.                 )
  756.             );
  757.             foreach ($senderSettingsDataQry as $item) {
  758.                 $senderSettingsData[$item->getHash()] = array(
  759.                     'name' => $item->getName(),
  760.                     'hash' => $item->getHash(),
  761.                     'email' => $item->getEmail(),
  762.                     'smtpServer' => $item->getSmtpServer(),
  763.                     'smtpPort' => $item->getSmtpPort(),
  764.                     'encryptionMethod' => $item->getEncryptionMethod(),
  765.                     'userName' => $item->getUserName(),
  766.                     'password' => $item->getPassword(),
  767.                     'valid' => $item->getValid(),
  768.                     'CompanyId' => $item->getCompanyId(),
  769.                 );
  770.             }
  771.             return new JsonResponse(
  772.                 array(
  773.                     'success' => true,
  774.                     'companyId' => $companyId,
  775.                     'senderVarieties' => $senderVarieties,
  776.                     'senderSettingsData' => $senderSettingsData,
  777.                 )
  778.             );
  779.         }
  780.         if ($request->isMethod('post')) {
  781.             $post $request->request;
  782.             $settingsCompanyId $post->get('companyId');
  783.             $hash $post->get('hash');
  784.             $name $post->get('name');
  785.             $userName $post->get('userName');
  786.             $email $post->get('email');
  787. //            $valid=$post->get('valid');
  788.             $password $post->get('password');
  789.             $smtpServer $post->get('smtpServer');
  790.             $smtpPort $post->get('smtpPort');
  791.             $encryptionMethod $post->get('encryptionMethod');
  792.             foreach ($hash as $key => $hashValue) {
  793.                 $exists 0;
  794.                 $valid 0;
  795.                 $new $em->getRepository('ApplicationBundle\\Entity\\EmailSenderSettings')->findOneBy(
  796.                     array(
  797.                         'CompanyId' => $settingsCompanyId,
  798.                         'hash' => $hashValue
  799.                     )
  800.                 );
  801.                 if ($new)
  802.                     $exists 1;
  803.                 else
  804.                     $new = new EmailSenderSettings;
  805.                 $emailValue explode(','$email[$key])[0];
  806.                 $emailValue filter_var($emailValueFILTER_SANITIZE_EMAIL);
  807.                 $emailValue filter_var($emailValueFILTER_VALIDATE_EMAIL);
  808.                 if ($emailValue) {
  809.                     $valid 1;
  810.                 }
  811.                 $new->setCompanyId($settingsCompanyId);
  812.                 $new->setHash($hashValue);
  813.                 $new->setValid($valid);
  814.                 $new->setName($name[$key]);
  815.                 $new->setEmail($emailValue);
  816.                 $new->setUserName($userName[$key]);
  817.                 $new->setPassword($password[$key]);
  818.                 $new->setSmtpServer($smtpServer[$key]);
  819.                 $new->setSmtpPort($smtpPort[$key]);
  820.                 $new->setTimeStampOfForm((new \DateTime())->format('U'));
  821.                 $new->setEncryptionMethod($encryptionMethod[$key]);
  822.                 if (!$exists) {
  823.                     $em->persist($new);
  824.                 }
  825.                 $em->flush();
  826.             }
  827.             // cp-shell email-settings form posts redirectTo to return to the shell.
  828.             if ($post->get('redirectTo')) {
  829.                 return $this->redirect($post->get('redirectTo'));
  830.             }
  831.         }
  832.         if ($companyId == || $companyId == $this->getLoggedUserCompanyId($request)) {
  833.             $companyId $this->getLoggedUserCompanyId($request);
  834.             $company $this->getDoctrine()
  835.                 ->getRepository('ApplicationBundle\\Entity\\Company')
  836.                 ->findOneBy(
  837.                     array(
  838.                         'id' => $companyId
  839.                     )
  840.                 );
  841.         } else {
  842.             $company $this->getDoctrine()
  843.                 ->getRepository('ApplicationBundle\\Entity\\Company')
  844.                 ->findOneBy(
  845.                     array(
  846.                         'id' => $companyId
  847.                     )
  848.                 );
  849.         }
  850. //        var_dump($company);
  851. //        print_r($type_list);
  852.         return $this->render('@System/pages/email_sender_settings.html.twig',
  853.             array(
  854.                 'page_header' => 'Email Senders',
  855.                 'page_title' => 'Email Senders',
  856.                 'page_header_sub' => 'Settings',
  857.                 'company_list' => $this->getDoctrine()
  858.                     ->getRepository('ApplicationBundle\\Entity\\Company')
  859.                     ->findBy(
  860.                         array(//                            'id'=>$companyId
  861.                         )
  862.                     ),
  863.                 'companyId' => $companyId,
  864.             ));
  865.     }
  866.     public function EditCompanyAction(Request $request$id)
  867.     {
  868. //        $employee= new Employee();
  869.         if ($id == || $id == $this->getLoggedUserCompanyId($request)) {
  870.             $companyId $this->getLoggedUserCompanyId($request);
  871.             $company $this->getDoctrine()
  872.                 ->getRepository('ApplicationBundle\\Entity\\Company')
  873.                 ->findOneBy(
  874.                     array(
  875.                         'id' => $companyId
  876.                     )
  877.                 );
  878.         } else {
  879.             $company $this->getDoctrine()
  880.                 ->getRepository('ApplicationBundle\\Entity\\Company')
  881.                 ->findOneBy(
  882.                     array(
  883.                         'id' => $id
  884.                     )
  885.                 );
  886.         }
  887. //        var_dump($company);
  888. //        print_r($type_list);
  889.         $country_list $this->getDoctrine()
  890.             ->getRepository('ApplicationBundle\\Entity\\Countries')
  891.             ->findBy(array(), array('nameEn' => 'ASC'));
  892.         return $this->render('@System/pages/edit_company.html.twig',
  893.             array(
  894.                 'page_header' => 'Company Info',
  895.                 'page_title' => 'Company Info',
  896.                 'page_header_sub' => 'Edit',
  897.                 'company_id' => $company->getId(),
  898.                 'dark_vibrant' => $company->getDarkVibrant(),
  899.                 'light_vibrant' => $company->getLightVibrant(),
  900.                 'vibrant' => $company->getVibrant(),
  901.                 'company_type' => $company->getCompanyType(),
  902.                 'company_name' => $company->getName(),
  903.                 'address' => $company->getAddress(),
  904.                 's_address' => $company->getShippingAddress(),
  905.                 'b_address' => $company->getBillingAddress(),
  906.                 'company_image' => $company->getImage(),
  907.                 'motto' => $company->getMotto(),
  908.                 'i_footer' => $company->getInvoiceFooter(),
  909.                 'g_footer' => $company->getGeneralFooter(),
  910.                 'company_tin' => $company->getCompanyTin(),
  911.                 'company_bin' => $company->getCompanyBin(),
  912.                 'company_reg' => $company->getCompanyReg(),
  913.                 'company_tl' => $company->getCompanyTl(),
  914.                 'ait_certificate_no' => $company->getAitCertificateNo(),
  915.                 'sms_enabled' => $company->getSmsNotificationEnabled(),
  916.                 'sms_settings' => $company->getSmsSettings(),
  917.                 'country_id' => $company->getCountryId(),
  918.                 'country_list' => $country_list,
  919.             ));
  920.     }
  921.     public function UpdateCompanyAction(Request $request)
  922.     {
  923. //        $product=new Product();
  924.         $post $request->request;
  925.         $company $this->getDoctrine()
  926.             ->getRepository('ApplicationBundle\\Entity\\Company')
  927.             ->findOneBy(
  928.                 array(
  929.                     'id' => $post->get('id')
  930.                 )
  931.             );
  932. //        var_dump($post);
  933. //        var_dump($company);
  934. //        var_dump($company->getName);
  935. //        var_dump($post->get('name'));
  936.         $company->setName($post->get('name'));
  937.         $company->setCompanyType($post->get('company_type'));
  938.         $company->setAddress($post->get('address'));
  939.         $company->setDarkVibrant($post->get('dark_vibrant'));
  940.         $company->setLightVibrant($post->get('light_vibrant'));
  941.         $company->setVibrant($post->get('vibrant'));
  942.         $company->setShippingAddress($post->get('s_address'));
  943.         $company->setBillingAddress($post->get('b_address'));
  944.         $company->setMotto($post->get('motto'));
  945.         $company->setInvoiceFooter($post->get('i_footer'));
  946.         $company->setGeneralFooter($post->get('g_footer'));
  947.         $company->setCompanyReg($post->get('company_reg'''));
  948.         $company->setCompanyTin($post->get('company_tin'''));
  949.         $company->setCompanyBin($post->get('company_bin'''));
  950.         $company->setCompanyTl($post->get('company_tl'''));
  951.         $company->setAitCertificateNo($post->get('ait_certificate_no'''));
  952.         // Company secretarial particulars (statutory calendar / ACRA AR).
  953.         if ($post->has('uen')) { $company->setUen($post->get('uen''') ?: null); }
  954.         if ($post->has('ssic_code')) { $company->setSsicCode($post->get('ssic_code''') ?: null); }
  955.         if ($post->has('financial_year_end')) { $company->setFinancialYearEnd($post->get('financial_year_end''') ?: null); }
  956.         if ($post->has('incorporation_date')) {
  957.             $incDate trim((string) $post->get('incorporation_date'''));
  958.             $company->setIncorporationDate($incDate !== '' ? new \DateTime($incDate) : null);
  959.         }
  960.         $company->setSmsNotificationEnabled($post->get('sms_enabled'));
  961.         $company->setSmsSettings($post->get('sms_settings'));
  962.         $countryIdPost $post->get('country_id'null);
  963.         $company->setCountryId(($countryIdPost === null || $countryIdPost === '') ? null : (int) $countryIdPost);
  964.         $path "";
  965.         foreach ($request->files as $uploadedFile) {
  966. //            if($uploadedFile->getImage())
  967. //                var_dump($uploadedFile->getFile());
  968. //                var_dump($uploadedFile);
  969.             if ($uploadedFile != null) {
  970. //                $fileName = md5(uniqid()) . '.' . $uploadedFile->guessExtension();
  971.                 $fileName 'company_image' $company->getAppId() . '.' $uploadedFile->guessExtension();
  972.                 $path $fileName;
  973.                 $upl_dir $this->container->getParameter('kernel.root_dir') . '/../web/uploads/CompanyImage/';
  974.                 if ($company->getImage() != null && $company->getImage() != '' && file_exists($this->container->getParameter('kernel.root_dir') . '/../web' $company->getImage())) {
  975.                     unlink($this->container->getParameter('kernel.root_dir') . '/../web' $company->getImage());
  976.                 }
  977.                 if (!file_exists($upl_dir)) {
  978.                     mkdir($upl_dir0777true);
  979.                 }
  980.                 $file $uploadedFile->move($upl_dir$path);
  981.             }
  982.         }
  983. //        print_r($file);
  984.         if ($path != "")
  985.             $company->setImage('/uploads/CompanyImage/' $path);
  986.         $em $this->getDoctrine()->getManager();
  987.         $em->persist($company);
  988.         $em->flush();
  989.         // cp-shell company-profile form posts a redirectTo so the user lands back
  990.         // in the cp-shell; legacy form omits it and returns to the edit page.
  991.         $redirectTo $post->get('redirectTo');
  992.         if ($redirectTo) {
  993.             return $this->redirect($redirectTo);
  994.         }
  995.         $url $this->generateUrl('edit_company_page');
  996.         return $this->redirect($url "/" $post->get('id'));
  997.     }
  998.     public function UserPermissionAction(Request $request$id)
  999.     {
  1000.         $user_id $id;
  1001.         $em $this->getDoctrine()->getManager();
  1002.         $iv '1234567812345678';
  1003.         $pass '_enc_';
  1004.         $suffix '_enpaac_';
  1005.         $userId $user_id;
  1006.         if (!is_numeric($user_id)) {
  1007.             if (stripos($user_id$suffix) !== false) {
  1008.                 $user_id str_ireplace($suffix''$user_id);
  1009.                 if (stripos($user_id'_FSLASH_') !== false) {
  1010.                     $user_id str_ireplace('_FSLASH_''/'$user_id);
  1011.                 }
  1012.                 $userId openssl_decrypt(base64_decode($user_id), "AES-128-CBC"$passOPENSSL_RAW_DATA$iv);
  1013.             } else {
  1014.                 $userId $this->get('url_encryptor')->decrypt($user_id);
  1015.             }
  1016.         }
  1017. //        $this->get('url_encryptor')->decrypt($user_id);
  1018.         if ($request->isMethod('POST')) {
  1019.             // Check if its basic info
  1020. //            if ($request->query->get('post_type', '') == "basic_info")
  1021.             {
  1022.                 $this->get('user_module')->updateUser(
  1023.                     $userId,
  1024.                     $request->request->get('name'),
  1025.                     $request->request->has('email') ? $request->request->get('email') : '_UNCHANGED_',
  1026.                     $request->request->has('username') ? $request->request->get('username') : '_UNCHANGED_',
  1027.                     $request->request->get('password'),
  1028.                     $request->request->get('status'),
  1029.                     $request->request->get('userType'),
  1030.                     $request->request->get('supervisorId'),
  1031.                     $request->request->get('defaultRoute'),
  1032.                     $request->request->get('branchIdList'),
  1033.                     $request->request->has('allModuleAccessFlag') ? 0,
  1034.                     $this->getLoggedUserLoginId($request));
  1035.                 $employee $em->getRepository('ApplicationBundle\\Entity\\Employee')->findOneBy(array('userId' => $userId));
  1036.                 $employeeDetails $em->getRepository('ApplicationBundle\\Entity\\EmployeeDetails')->findOneBy(array('userId' => $userId));
  1037.                 $superVisor $em->getRepository('ApplicationBundle\\Entity\\SysUser')->findOneBy(array('userId' => $request->request->get('supervisorId'0)));
  1038.                 $superVisorId 0;
  1039.                 if ($superVisor)
  1040.                     $superVisorId $superVisor->getUserId();
  1041.                 if ($employee) {
  1042.                     $employee->setSupervisorId($superVisorId);
  1043.                     $em->persist($employee);
  1044.                 }
  1045.                 if ($employeeDetails) {
  1046.                     $employeeDetails->setSupervisor($superVisorId);
  1047.                     $employeeDetails->setEmpStatus($request->request->get('status'));
  1048.                     $em->persist($employeeDetails);
  1049.                 }
  1050.                 $em->flush();
  1051.                 // Check if its permission
  1052.             }
  1053. //            if ($request->query->get('post_type', '') == "permission")
  1054.             {
  1055.                 $this->get('user_module')->updateUserPosition($userId$request->get('permission') ? $request->get('permission') : ''$this->getLoggedUserLoginId($request));
  1056.             }
  1057. //            if ($request->query->get('post_type', '') == "access_restriction_option")
  1058.             {
  1059.                 $this->get('user_module')->updateUserAccessSettings($userId$request->request$this->getLoggedUserLoginId($request));
  1060.             }
  1061. //            if ($request->query->get('post_type', '') == "module_access")
  1062.             {
  1063.                 $this->get('user_module')->updateUserModuleList($userId$request->request->get('modules'), $request->request->get('selectionType'), $this->getLoggedUserLoginId($request));
  1064.             }
  1065. //            return $this->redirectToRoute("system_admin_user_permission", array("user_id"=>$user_id));
  1066.             return new JsonResponse(array('success' => true));
  1067.         }
  1068.         $getUserInfo $this->get('user_module')->getUserInfo($userId);
  1069.         $userAccessData Users::getUserApplicationAccessSettings($this->getDoctrine()->getManager(), $userId1);
  1070.         if (!is_array($getUserInfo)) {
  1071.             $this->addFlash(
  1072.                 'error',
  1073.                 'No user found.'
  1074.             );
  1075.             return $this->redirectToRoute("system_admin_user_list");
  1076.         }
  1077.         $userList $this->get('user_module')->showUserList();
  1078.         // Hide explicitly-retired modules (sys_module.status = 0) from the permission grid
  1079.         // so users can't be granted access to outdated/old pages. status IS NULL or non-zero
  1080.         // stays visible (tenants that never set the flag are unaffected).
  1081.         $modules $this->getDoctrine()
  1082.             ->getRepository('ApplicationBundle\\Entity\\SysModule')
  1083.             ->createQueryBuilder('m')
  1084.             ->where('m.level = 1')
  1085.             ->andWhere('(m.status IS NULL OR m.status <> 0)')
  1086.             ->getQuery()
  1087.             ->getResult();
  1088.         $module_data = [];
  1089.         $module_data_by_parent_id = [];
  1090.         $module_data_array = [];
  1091.         $user_modules_array = [];
  1092.         $selectionType 0;
  1093.         $user_modules_array $getUserInfo['moduleIds'];
  1094. //                if($modules==null)
  1095. //                    $modules=[];
  1096. //                if(!empty($modules))
  1097.         if ($user_modules_array != null//we will check for null rather than empty as user might have no access to anything
  1098.         {
  1099.             $selectionType 1;
  1100.         }
  1101.         $position_modules = [];
  1102.         $position_modules_by_position = [];
  1103.         $position_modules_array = [];
  1104.         foreach ($modules as $entry) {
  1105.             $dt = array(
  1106.                 'id' => $entry->getModuleId(),
  1107.                 'name' => $entry->getModuleName(),
  1108.                 'route' => $entry->getModuleRoute(),
  1109.                 'parentId' => $entry->getParentId()
  1110.             );
  1111.             $module_data[$entry->getModuleId()] = $dt;
  1112.             $module_data_by_parent_id[$entry->getParentId()] = $dt;
  1113.             $module_data_array[] = $dt;
  1114.         }
  1115.         $cur_pos_modules $this->getDoctrine()
  1116.             ->getRepository('ApplicationBundle\\Entity\\SysDeptPositionDefaultModule')
  1117.             ->findAll();
  1118.         foreach ($cur_pos_modules as $entry) {
  1119.             $dt = array(
  1120.                 'id' => $entry->getId(),
  1121.                 'positionId' => $entry->getPositionId(),
  1122. //                'dept'=>$entry->getDepartmentId(),
  1123.                 'data' => json_decode($entry->getModuleIds(), true)
  1124.             );
  1125.             $position_modules[$entry->getId()] = $dt;
  1126.             $position_modules_by_position[$entry->getPositionId()] = $dt;
  1127.             $position_modules_array[] = $dt;
  1128.         }
  1129.         $userList $this->get('user_module')->showUserListDesc();
  1130.         return $this->render('@System/pages/user_permission.html.twig',
  1131.             array(
  1132.                 'page_title' => 'Edit User (' $getUserInfo['name'] . ')',
  1133.                 'user_info' => $getUserInfo,
  1134.                 'user_list' => $userList,
  1135.                 'userAccessData' => $userAccessData,
  1136.                 'module_data_array' => $module_data_array,
  1137.                 'module_data' => $module_data,
  1138.                 'parent_modules' => ModuleConstant::$parentModuleList,
  1139.                 'module_data_by_parent_id' => $module_data_by_parent_id,
  1140.                 'warehouse_action_list' => Inventory::warehouse_action_list($em$this->getLoggedUserCompanyId($request), 'object'),
  1141.                 'warehouse_list' => Inventory::WarehouseList($em),
  1142.                 'production_process_list' => ProductionM::ProcessList($this->getDoctrine()->getManager(), $this->getLoggedUserCompanyId($request)),
  1143.                 'position_modules' => $position_modules,
  1144.                 'position_modules_by_position' => $position_modules_by_position,
  1145.                 'position_modules_array' => $position_modules_array,
  1146.                 'user_modules_array' => $user_modules_array,
  1147.                 'selection_type' => $selectionType
  1148.             )
  1149.         );
  1150.     }
  1151.     public function ModulePositionAction(Request $request)
  1152.     {
  1153.         return $this->render('@System/pages/module_status.html.twig',
  1154.             array(
  1155.                 'page_title' => 'Module',
  1156.             )
  1157.         );
  1158.     }
  1159. }