403Webshell
Server IP : 103.234.187.230  /  Your IP : 216.73.216.216
Web Server : Apache
System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/b2bzend/application/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2bzend/application/controllers/StaffController.php
<?php

/*
 * Catabatic Technology Pvt. Ltd.
 * File Name :StaffController.php
 * File Description :Staff controller managed all data related to staff
 * Created By : Pooja Choudhary
 * Created Date: 28-June-2016
 */

class StaffController extends Catabatic_ValidateGtx {

    public function init() {
        parent::init();
        $aConfig = $this->getInvokeArg('bootstrap')->getOptions();
        $this->siteUrl = $aConfig['bootstrap']['siteUrl'];
        $this->smtpUserName = $aConfig['smtpUserName'];
        $this->smtpPassword = $aConfig['smtpPassword'];
        $this->smtpPort = $aConfig['smtpPort'];
        $this->smtpHost = $aConfig['smtpHost'];
        $this->fromEmail = $aConfig['fromEmail'];
        $this->fromName = $aConfig['fromName'];
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $this->intLoggedinUserAgencySysId = $sessionLogin_user->intLoggedinUserAgencySysId;
        $this->agencyType = (int) $sessionLogin_user->agencyDetails['AgencyType'];
        $this->intLoggedinUserId = $sessionLogin_user->intLoggedinUserId;
        $this->SENDREGISTERSMSCONFIG = Catabatic_Helper::getSENDREGISTERSMSCONFIG();
    }

    public function indexAction() {
        $AgencySysId = (null !== $this->getRequest()->getParam('aid')) ? base64_decode($this->sanitize_data($this->getRequest()->getParam('aid'))) : $this->intLoggedinUserAgencySysId;
        $objStaff = new Travel_Model_TblAgencyStaff();
        if ((null !== $this->getRequest()->getParam('aid'))) {
            $AgencyStaffList = $objStaff->getAgencyStaffList('', '', $AgencySysId, 1);
        } else {
            $AgencyStaffList = $objStaff->getAgencyStaffList('', '', $AgencySysId, 0);
        }
        $this->view->AgencyStaffList = $AgencyStaffList;
        $page = $this->_getParam('page', 1);
        $paginator = Zend_Paginator::factory($AgencyStaffList);
        $paginator->setItemCountPerPage(GRID_PER_PAGE_RECORD_COUNT);
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator = $paginator;
        $msg = $this->_getParam('msg');
        $this->view->msg = $msg;
        $this->view->aid = (null !== $this->getRequest()->getParam('aid')) ? ($this->sanitize_data($this->getRequest()->getParam('aid'))) : '';
        $this->view->messages = $this->_helper->flashMessenger->getMessages();
    }

    /*
     * addStaffAction(); is main action used to add Agency's Staff members
     * Created By- Pooja
     * Created on- 01 July 2016
     */

    public function addStaffAction() {
        $id = $this->getRequest()->getParam('id');
        $isb2b = $this->getRequest()->getParam('isb2b');
        $maId = $this->getRequest()->getParam('maId');
        $this->view->maId = $maId;
        $this->view->isb2b = $isb2b;
        $this->view->UserId = $id;
        $objStaff = new Travel_Model_TblAgencyStaff();
        $objAgency = new Travel_Model_TblAgency();
        $UserData = $objStaff->getUserDataByUserId(base64_decode($id));
        $AgencyDetails = $objAgency->getUserDataByAgency(base64_decode($maId));
        //print_r($UserData);die;
        $this->view->AgencyDetails = $AgencyDetails;
    }

    /*
     * editStaffAction(); is main action used to edit Agency's Staff members
     * Created By- Pooja
     * Created on- 01 July 2016
     */

    public function editStaffAction() {
        $id = $this->getRequest()->getParam('id');
//        print_r($UserData);
//        $this->view->UserData = $UserData;
        $id = $this->getRequest()->getParam('id');
        $isb2b = $this->getRequest()->getParam('isb2b');
        $maId = $this->getRequest()->getParam('maId');
        $this->view->maId = $maId;
        $this->view->isb2b = $isb2b;
        $this->view->UserId = $id;
        $objStaff = new Travel_Model_TblAgencyStaff();
        $objAgency = new Travel_Model_TblAgency();
        $UserData = $objStaff->getUserDataByUserId(base64_decode($id));
        $AgencyDetails = $objAgency->getUserDataByAgency(base64_decode($maId));
        $this->view->AgencyDetails = $AgencyDetails;
        $this->view->UserData = $UserData;
    }

    /*
     * userLoginAndRoleAction(); is used to add user login details
     * Created By- Pooja
     * Created on- 01 July 2016
     */

    public function userLoginAndRoleAction() {
        //set layout
        $this->_helper->layout->disableLayout();
        $isActive = 1;
        $objDept = new Travel_Model_TblAgencyDept();
        $objAgency = new Travel_Model_TblAgency();
        $objRole = new Travel_Model_TblAgencyUserRole();
        $marketPlaceList = $objAgency->getAgencyMarketPlaceList(1, $this->intLoggedinUserAgencySysId, '');
        if ($this->getRequest()->getParams()) {
            $StaffUserId = base64_decode($this->getRequest()->getParam('StaffUserId'));
            $isb2b = $this->getRequest()->getParam('isb2b');
            $maId = $this->getRequest()->getParam('maId');
            $objStaff = new Travel_Model_TblAgencyStaff();

            $userData = $objStaff->getUserDataByUserId($StaffUserId);
            $this->view->userData = $userData;
            $this->view->isb2b = $isb2b;
            $this->view->maId = $maId;
//            echo $StaffUserId; die;
            $AgencyDetails = $objAgency->getUserDataByAgency(base64_decode($maId));
            //print_r($userData);die;
            $this->view->AgencyDetails = $AgencyDetails;
        }
        $this->view->marketPlaceList = $marketPlaceList;
        $this->view->departmentList = $objDept->getDepartmentList($isActive);
        //print_r($objRole->getRoleList($isActive));
        $this->view->roleList = $objRole->getRoleList($isActive);
    }

    /*
     * moreInformationAction(); is used to add user's information
     * Created By- Pooja
     * Created on- 01 July 2016
     */

    public function moreInformationAction() {
        //set layout
        $this->_helper->layout->disableLayout();
        if ($this->getRequest()->getParams()) {
            $StaffUserId = base64_decode($this->getRequest()->getParam('StaffUserId'));
            $maid = base64_decode($this->getRequest()->getParam('maId'));

            $objStaff = new Travel_Model_TblAgencyStaff();
            $this->view->userData = $objStaff->getUserDataByUserId($StaffUserId);
            //echo "<pre>";print_r($this->view->userData);exit;
            $UserRole = $this->view->userData['UserRole'];
//            echo $StaffUserId; die;
        }
        $isActive = 1;
        $objStaff = new Travel_Model_TblAgencyStaff();
        $isB2BAgent = (isset($maid) && $maid > 0) ? 1 : 0;
        $AgencySysId = $this->intLoggedinUserAgencySysId;
        //$this->view->AgencyStaffList = $objStaff->getAgencyStaffListUserRole($isActive, @$StaffUserId,$AgencySysId,$isB2BAgent);
        $this->view->AgencyStaffList = $objStaff->getAgencyStaffListUserRolewithReport($isActive, @$StaffUserId, $AgencySysId, $isB2BAgent, $UserRole);
    }

    /*
     * staffAddressAction(); is used to add user's address
     * Created By- Pooja
     * Created on- 01 July 2016
     */

    public function staffAddressAction() {
        //set layout
        $this->_helper->layout->disableLayout();

        if ($this->getRequest()->getParams()) {
            $isb2b = $this->getRequest()->getParam('isb2b');
            $StaffUserId = base64_decode($this->getRequest()->getParam('StaffUserId'));
            $objStaff = new Travel_Model_TblAgencyStaff();
            $this->view->userData = $objStaff->getUserDataByUserId($StaffUserId);
            $this->view->isb2b = $isb2b;
//            echo $StaffUserId; die;
        }
    }

    /*
     * signatureAction(); is used to add user's signature
     * Created By- Pooja
     * Created on- 01 July 2016
     */

    public function signatureAction() {
        //set layout
        $this->_helper->layout->disableLayout();

        if ($this->getRequest()->getParams()) {
            $StaffUserId = base64_decode($this->getRequest()->getParam('StaffUserId'));
            $objStaff = new Travel_Model_TblAgencyStaff();
            $this->view->userData = $objStaff->getUserDataByUserId($StaffUserId);
//            echo $StaffUserId; die;
        }
    }

    /*
     * viewStaffAction(); is used to view details of Agency's Staff member
     * Created By- Pooja
     * Created on- 01 July 2016
     */

    public function viewStaffAction() {
        if ($this->getRequest()->getParams()) {
            $StaffUserId = base64_decode($this->getRequest()->getParam('id'));
            $maId = (null !== $this->getRequest()->getParam('maId')) ? ($this->sanitize_data($this->getRequest()->getParam('maId'))) : '';
            $isb2b = (null !== $this->getRequest()->getParam('isb2b')) ? ($this->sanitize_data($this->getRequest()->getParam('isb2b'))) : '';
            $objStaff = new Travel_Model_TblAgencyStaff();
            $userData = $objStaff->getUserDataByUserId($StaffUserId);
            echo "<pre>";
            $ReportingTo = $objStaff->getUserDetailsById($userData['ReportingToSysId']);
            $this->view->maId = $maId;
            $this->view->isb2b = $isb2b;
            $this->view->userData = $userData;
            $this->view->ReportingTo = $ReportingTo;

//            echo $StaffUserId; die;
        } else {
            $this->_helper->redirector('index', 'staff', 'default');
        }
    }

    /*
     * saveStaffUserDetailsAction(); is used to save userLoginAndRoleAction()'s data
     * Created By- Pooja
     * Created on- 04 July 2016
     */

    public function saveStaffUserDetailsAction() {
        //disable layout
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        if ($this->getRequest()->isXmlHttpRequest()) {
            $getData = $this->getRequest()->getParams();
            // echo "<pre>";print_r($getData);exit;
//            $date = new Zend_Date();
            $currentDate = date('Y-m-d H:i:s');

            $CustomerSysId = 0;


            $objStaff = new Travel_Model_TblAgencyStaff();
            $userSysId = base64_decode($getData['id']);
            if (empty($getData['first_name']) || empty($getData['last_name'])) {
                echo json_encode(array('result' => 5));
                exit;
            }
            $staff_role = $getData['staff_role'] ? $this->sanitize_data($getData['staff_role']) : 0;
            //add b2b agency code added by amit on 04 nov 2017 at 1:44 PM
            $objAgency = new Travel_Model_TblAgency();
            $NewAgencySysId = '';
            if (!empty($getData['is_btobagent']) && $staff_role == 0) {

                $agencyName = $getData['b2bagency_name'];
                $countryId = '';
                $selectState = '';
                $cityId = '';
                $contactName = $getData['first_name'];
                $emailId = $getData['emailId'] ? trim($getData['emailId']) : '';
                $mobileNo = $getData['mobilePhone'] ? trim($getData['mobilePhone']) : '';
                $countrycode = $getData['countrycode'] ? trim($getData['countrycode']) : '';
                $panNo = !empty($getData['b2bagency_pan']) ? $this->sanitize_data($getData['b2bagency_pan']) : '';
                $marketPlaceSysId = !empty($getData['marketPlaceSysId']) ? $this->sanitize_data($getData['marketPlaceSysId']) : '';
                $shortDetail = '';

                //get verify response data
                $agencyDetails = $objAgency->isB2BAgencyEmailExists(trim($emailId), $this->intLoggedinUserAgencySysId);
                //print_r($agencyDetails);die;
                if (count($agencyDetails) == 0) {
                    $currentDate = date('Y-m-d H:i:s');
                    //save agency details to database
                    $agencyData = array(
                        'MasterAgencySysId' => $this->intLoggedinUserAgencySysId,
                        'agencyName' => $agencyName,
                        'selectCountry' => $countryId,
                        'selectState' => $selectState,
                        'selectCity' => $cityId,
                        'contactName' => $contactName,
                        'emailId' => $emailId,
                        'mobileNo' => $mobileNo,
                        'countrycode' => $countrycode,
                        'shortDetail' => $shortDetail,
                        'PanCardNo' => $panNo,
                        'AgencyMarketPlaceSysId' => $marketPlaceSysId,
                        'IsActive' => 1,
                        'CreateDate' => $currentDate
                    );

                    $NewAgencySysId = $objAgency->registerAgency($agencyData, 1);

                    //add agency role
                    $agencyUserRoleArr = unserialize(AGENCY_USER_ROLE);

                    //add user role 
                    $agencyPrimaryUserRoleData = Array(
                        'AgencySysId' => $NewAgencySysId,
                        'RoleTitle' => $agencyUserRoleArr[1],
                        'IsAdmin' => 1,
                        'IsAbleToManageMember' => 1
                    );
                    $userRoleId = $objAgency->addUserRole($agencyPrimaryUserRoleData);
                    //$staff_role=$userRoleId;
                    $staff_role = 0;

                    $emailData = base64_encode($emailId);
                    $link = base64_encode('byEmail');
                    if ($this->SENDREGISTERSMSCONFIG == 1) {
                        $url = $this->siteUrl . "register/verify-contact-data/data/$emailData/link/$link";
                    } else {
                        $url = $this->siteUrl . "register/verify-contact-email/data/$emailData/link/$link";
                    }
                    $params = array('agent_name' => ucfirst($contactName), 'verification_link' => $url);
                    #Set subject
                    $subject = 'You\'re almost there, verify your email with ' . SITE_NAME;
                    $html = new Zend_View();
                    $html->setScriptPath(APPLICATION_PATH . '/views/emails/');
                    $html->assign($params);
                    $bodyText = $html->render('agent_registration.phtml');
                    $emailData = array('fromEmail' => $this->fromEmail, 'fromName' => $this->fromName, 'subject' => $subject, 'to' => array($emailId), 'bodyHtml' => $bodyText, 'bodyText' => '');
                    try {
                        //echo "success";
                        $arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
                        $arrEmailStatistics = array(
                            "TPSysId" => 0,
                            "TypeSysId" => 1, // 1 For Email 2 For SMS
                            "AgencySysId" => 0,
                            "AgentSysId" => 0,
                            "Title" => $bodyText,
                            "Source" => $arrEmailStatisticsType[2], // 6 For Misc
                            "Status" => 0,
                            "RefSysId" => "",
                            "RefSysStatus" => "",
                            "CreateDate" => date('Y-m-d H:i:s')
                        );
                        //$this->mailSentByElastice($emailData,$arrEmailStatistics);
                        //email alert for gtx admin
                        $bodyTextForAgent = 'New agency is registered on <a href="' . SITE_FULL_URL . 'admin">' . SITE_FULL_URL . '/admin</a> !';
                        $emailDataFOrGTXADMIN = array('fromEmail' => $emailId, 'fromName' => $contactName, 'subject' => 'New Registration alert on GTX', 'to' => array('amit.k@catpl.co.in', 'pooja@catpl.co.in', 'gaurav@catpl.co.in'), 'bodyHtml' => $bodyTextForAgent, 'bodyText' => '');
                        //$this->mailSentByElastice($emailDataFOrGTXADMIN,$arrEmailStatistics);
                    } catch (Exception $err) {
                        
                    }
                } else {
                    $NewAgencySysId = $agencyDetails['AgencySysId'];
                }
            }
            //#end of code
            $AgencySysId = $this->intLoggedinUserAgencySysId;
            if (!empty($getData['is_btobagent'])) {
                $AgencySysId = $NewAgencySysId;
            }
            $AgencyCode = '';
            $IsB2BAgent = !empty($getData['is_btobagent']) ? $this->sanitize_data($getData['is_btobagent']) : 0;
            if (!empty($getData['B2BAgencyId'])) {
                $AgencySysId = base64_decode($getData['B2BAgencyId']);
                $IsB2BAgent = 1;
                $getAgencyCode = $objStaff->getLastAgencyCode($AgencySysId);
                $AgencyCode = (trim($getAgencyCode['AgencyCode']) != '') ? $getAgencyCode['AgencyCode'] : 0;
            } else {
                $IsB2BAgent = !empty($getData['is_btobagent']) ? $this->sanitize_data($getData['is_btobagent']) : 0;
            }



            $resUserData = $objStaff->getUserDataByUserId(@$userSysId);
            if (isset($getData['b2bagency_name']) && !empty($getData['b2bagency_name'])) {
                $getagencyname = trim($this->sanitize_data($getData['b2bagency_name']));
                $getAgencyCode = $objStaff->checkExistAgencyCode($getagencyname);
                if ($getAgencyCode['AgencyCode'] != '') {
                    $AgencyCode = (trim($getAgencyCode['AgencyCode']) != '') ? $getAgencyCode['AgencyCode'] : 1;
                    $remainingNumber = 5 - strlen($AgencySysId . $getAgencyCode['AgencyCode']);
                    $AgencyCode = str_pad($AgencyCode, $remainingNumber, '0', STR_PAD_LEFT);
                    $AgencyCode = (strlen($AgencyCode) == 5) ? $AgencyCode : $AgencySysId . $AgencyCode;
                } else {
                    $getAgencyCode = $objStaff->getLastAgencyCode();
                    $AgencyCode = (trim($getAgencyCode['AgencyCode']) != '') ? $getAgencyCode['AgencyCode'] + 1 : 1;
                    $remainingNumber = 5 - strlen($AgencySysId);
                    $AgencyCode = str_pad($AgencyCode, $remainingNumber, '0', STR_PAD_LEFT);
                    $AgencyCode = (strlen($AgencyCode) == 5) ? $AgencyCode : $AgencySysId . $AgencyCode;
                }
            }
            //echo "hhhhhh".$AgencyCode;
            //die;

            if (@$userSysId) { // update user details
                //print_r($objStaff->getUserDataByUserId(@$userSysId)); exit;
                $agencyUserDataForDb = array(
                    'AgencySysId' => $AgencySysId,
                    'FirstName' => $getData['first_name'] ? $this->sanitize_data($getData['first_name']) : 0,
                    'LastName' => $getData['last_name'] ? $this->sanitize_data($getData['last_name']) : 0,
                    'UserRole' => $staff_role,
                    'EmailId' => $getData['emailId'] ? trim($getData['emailId']) : 0,
                    'IsInsurance' => !empty($getData['is_insurance']) ? $this->sanitize_data($getData['is_insurance']) : 0,
                    'IsB2BAgent' => $IsB2BAgent,
                    'AgencyName' => !empty($getData['b2bagency_name']) ? $this->sanitize_data($getData['b2bagency_name']) : '',
                    'GSTIN' => !empty($getData['b2bagency_gstin']) ? $this->sanitize_data($getData['b2bagency_gstin']) : '',
                    'PanNumber' => !empty($getData['b2bagency_pan']) ? $this->sanitize_data($getData['b2bagency_pan']) : '',
                    'ContactNo1' => $getData['mobilePhone'] ? $this->sanitize_data(trim($getData['mobilePhone'])) : '',
                    'countrycode' => $getData['countrycode'] ? trim($getData['countrycode']) : '',
                    'AgencyCode' => !empty($AgencyCode) ? $this->sanitize_data($AgencyCode) : 0,
                    'UpdateDate' => $currentDate ? $currentDate : 0,
                );
                $objStaff->editUserDetails($agencyUserDataForDb, $userSysId);
                if ($staff_role == 0) {
                    $agencyDataForDb = array(
                        'Title' => !empty($getData['b2bagency_name']) ? $this->sanitize_data($getData['b2bagency_name']) : '',
                        'NickId' => !empty($getData['b2bagency_name']) ? $this->sanitize_data($getData['b2bagency_name']) : '',
                        'PrimaryEmail' => $getData['emailId'] ? trim($getData['emailId']) : '',
                        'PrimaryContactName' => $getData['first_name'] ? $this->sanitize_data($getData['first_name']) : '',
                        'ContactInfo' => $getData['mobilePhone'] ? $this->sanitize_data(trim($getData['mobilePhone'])) : '',
                        'countrycode' => $getData['countrycode'] ? trim($getData['countrycode']) : '',
                        'UpdateDate' => $currentDate ? $currentDate : '',
                    );
                    $objAgency->updateAgencyData($agencyDataForDb, $AgencySysId);
                }
                if (isset($getData['staff_department']) && $getData['staff_department'] != "") {
                    $staffDepartment = (int) $getData['staff_department'];
                    $checkResultOps = $objStaff->checkOps($staffDepartment);
                    if ($checkResultOps > 0) {
                        $isOps = isset($getData['is_operations']) ? $getData['is_operations'] : array();
                        $objStaff->addDeptPlanMap($staffDepartment, $isOps, $userSysId);
                    } else {
                        $objStaff->updateDeptPlanMap($staffDepartment, $userSysId);
                    }
                }
                if ($resUserData['DeptSysId']) {
                    if ($IsB2BAgent == 1) {
                        $deptMappingArr = array(
                            'DeptSysId' => $getData['staff_department'],
                        );
                    } else {
                        $deptMappingArr = array(
                            'DeptSysId' => $getData['staff_department'],
                            'RoleSysId' => $staff_role
                        );
                    }
                    $objStaff->editDeptUserMapping($deptMappingArr, $userSysId);
                } else {

                    if ($userSysId) {
                        $deptMappingArr = array(
                            'DeptSysId' => $getData['staff_department'],
                            'RoleSysId' => $staff_role
                        );
                        $objStaff->editDeptUserMapping($deptMappingArr, $userSysId);
                    } else {
                        $deptMappingArr = array(
                            'DeptSysId' => $getData['staff_department'],
                            'UserSysId' => $userSysId,
                            'RoleSysId' => $staff_role,
                            'ReportingToSysId' => 0,
                            'JoinDate' => $currentDate,
                            'ExitDate' => EMPTY_DATE,
                            'IsActive' => 1,
                            'IsMarkForDelete' => 0,
                            'IsApproved' => 1);

                        $objStaff->addDeptUserMapping($deptMappingArr);
                    }
                }

                $json = array('result' => 3, 'id' => base64_encode($userSysId));
                echo json_encode($json);
                exit;
            } else if (!$objStaff->isUserEmailExists(trim($getData['emailId']), '', $AgencySysId)) {
                //insert user details
//                $date = new Zend_Date();
                $currentDate = date('Y-m-d H:i:s');
                $oRandStrPass = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->generateRandomString(5);
                $userDataSignature = $objStaff->getUserDataByUserId($this->intLoggedinUserId);

                $agencyUserDataForDb = array(
                    'AgencySysId' => $AgencySysId,
                    'Designation' => '',
                    'IsfromSM' => 0,
                    'SMTypeId' => 0,
                    'SMId' => 0,
                    'UserId' => 0,
                    'EmpId' => 0,
                    'JoinDate' => $currentDate ? $currentDate : 0,
                    'ExitDate' => 0,
                    'UserName' => 0,
                    'FirstName' => $getData['first_name'] ? $this->sanitize_data($getData['first_name']) : 0,
                    'LastName' => $getData['last_name'] ? $this->sanitize_data($getData['last_name']) : 0,
                    'UserRole' => $staff_role,
                    'IsInsurance' => !empty($getData['is_insurance']) ? $this->sanitize_data($getData['is_insurance']) : 0,
                    'IsB2BAgent' => $IsB2BAgent,
                    'AgencyName' => !empty($getData['b2bagency_name']) ? $this->sanitize_data($getData['b2bagency_name']) : '',
                    'GSTIN' => !empty($getData['b2bagency_gstin']) ? $this->sanitize_data($getData['b2bagency_gstin']) : '',
                    'PanNumber' => !empty($getData['b2bagency_pan']) ? $this->sanitize_data($getData['b2bagency_pan']) : '',
                    'AgencyCode' => !empty($AgencyCode) ? $this->sanitize_data($AgencyCode) : 0,
                    'UserAccessLevelType' => 0,
                    'Password' => md5($oRandStrPass),
                    'RandStr' => $oRandStrPass,
                    'PasswordExpiryDate' => 0,
                    'IsPswExpire' => 0,
                    'EmailId' => $getData['emailId'] ? $this->sanitize_data($getData['emailId']) : 0,
                    'LastLoginTime' => 0,
                    'IsLogInNow' => 0,
                    'CreatedByUserSysId' => $this->intLoggedinUserAgencySysId,
                    'RandomCode' => 0,
                    'Gender' => 0,
                    'UserNickName' => 0,
                    'UserPicPath' => 0,
                    'ContactNo1' => $getData['mobilePhone'] ? trim($getData['mobilePhone']) : '',
                    'countrycode' => $getData['countrycode'] ? trim($getData['countrycode']) : '',
                    'ContactNo2' => '',
                    'UserDetails' => '',
                    'MacIp' => 0,
                    'UpdateDate' => $currentDate ? $currentDate : 0,
                    'RegisterDate' => $currentDate ? $currentDate : 0,
                    'IsMarkForDel' => 0,
                    'IsActive' => 1,
                    'IsApproved' => 1,
                    'PinCode' => '',
                    'Signature' => $userDataSignature['Signature']
                );

                //print_r($agencyUserDataForDb);
                $userSysId = $objStaff->addUserDetails($agencyUserDataForDb);


                if (isset($getData['staff_department']) && $getData['staff_department'] != "") {
                    $staffDepartment = (int) $getData['staff_department'];
                    $checkResultOps = $objStaff->checkOps($staffDepartment);
                    if ($checkResultOps > 0) {
                        $isOps = isset($getData['is_operations']) ? $getData['is_operations'] : array();
                        $objStaff->addDeptPlanMap($staffDepartment, $isOps, $userSysId);
                    } else {
                        $objStaff->updateDeptPlanMap($staffDepartment, $userSysId);
                    }
                }




                if (@$userSysId) {
                    $deptMappingArr = array(
                        'DeptSysId' => $getData['staff_department'],
                        'UserSysId' => $userSysId,
                        'RoleSysId' => $getData['staff_role'],
                        'ReportingToSysId' => 0,
                        'JoinDate' => $currentDate,
                        'ExitDate' => EMPTY_DATE,
                        'IsActive' => 1,
                        'IsMarkForDelete' => 0,
                        'IsApproved' => 1);

                    $objStaff->addDeptUserMapping($deptMappingArr);

                    // code for add b2b customer 
                    if ($IsB2BAgent == 1) {
                        $objAgency->checkAgencyWallet($AgencySysId, $userSysId);
                        $this->_crmcustomerObj = new Travel_Model_CRM_Customer();
                        $this->_crmagencyleadaccountObj = new Travel_Model_CRM_AgencyLeadAccount();
                        $this->_agencycustomerObj = new Travel_Model_CRM_AgencyCustomer();
                        $email = $getData['emailId'] ? $this->sanitize_data($getData['emailId']) : '';
                        $mobilenum = $getData['mobilePhone'] ? trim($getData['mobilePhone']) : '';
                        $countrycode = $getData['countrycode'] ? trim($getData['countrycode']) : '';
                        $fname = $getData['first_name'] ? $this->sanitize_data($getData['first_name']) : '';
                        $lname = $getData['last_name'] ? $this->sanitize_data($getData['last_name']) : '';
                        $salution = '';
                        $CRMCustSysId = "";
                        if (isset($email) && !empty($email)) {
                            $customerDetailsEmail = $this->_crmcustomerObj->ChkEmailWithResponseUpdate($email, $AgencySysId);
                        }
                        if (isset($mobilenum) && !empty($mobilenum)) {
                            $customerDetailsMobile = $this->_crmcustomerObj->ChkMobileWithResponse($mobilenum, $AgencySysId, '', $CRMCustSysId);
                        }
                        //            echo 'pppppp';print_r($customerDetailsMobile); die;
                        if (!empty($customerDetailsEmail) || !empty($customerDetailsMobile)) {
                            $status = 'success';
                            $CustomerSysId = isset($customerDetailsEmail['CustomerSysId']) ? $customerDetailsEmail['CustomerSysId'] : @$customerDetailsMobile['CustomerSysId'];
                        } else {
                            $status = 'failure';
                        }

                        //echo "hhhhh".($prevCustomerSysId).'lllll'.$CustomerSysIdS;die;;
                        ########************************************End Check user in system ********************************* */
                        ########************************************ If user not exist in system then insert****************** */
                        if ($status == 'failure') {
                            $leadsourceTitle = 'Agency';
                            $intLeadSourceSysId = $this->_crmcustomerObj->getLeadSource($this->intLoggedinUserAgencySysId, $leadsourceTitle); // for Master LeadSouce Creation
                            $leadsource = (isset($intLeadSourceSysId[0]['LeadSourceSysId']) && !empty($intLeadSourceSysId[0]['LeadSourceSysId'])) ? $intLeadSourceSysId[0]['LeadSourceSysId'] : 0;

                            $userArray = array(
                                'EmailId' => $email,
                                'Salutation' => 1,
                                'PrimaryContactNumber' => '',
                                'FullName' => $fname . ' ' . $lname,
                                'FirstName' => $fname,
                                'LastName' => $lname ? $lname : '',
                                'ActiveDate' => $currentDate,
                                'UpdatedDate' => $currentDate,
                                'CreatedDate' => $currentDate,
                                'IsApproved' => '1',
                                'IsActive' => '1',
                                'IsMarkForDelete' => '0'
                            );
                            //for create new customer
                            $CRMCustSysId = $this->_crmcustomerObj->addCustomer($userArray);
                            $userLeadArray = array(
                                'AgencySysId' => $this->intLoggedinUserAgencySysId,
                                'EmailId' => $email,
                                'Salutation' => $salution ? $salution : 0,
                                'PrimaryContactNumber' => $mobilenum ? $mobilenum : '',
                                'PrimaryContactNumber' => $countrycode ? $countrycode : '',
                                'FullName' => $fname . ' ' . $lname,
                                'FirstName' => $fname ? $fname : '',
                                'LastName' => $lname ? $lname : '',
                                'LeadSourceSysId' => $leadsource,
                                'LeadStageSysId' => "",
                                'AssignUserSysId' => $this->intLoggedinUserId,
                                'ActiveDate' => $currentDate,
                                'UpdatedDate' => $currentDate,
                                'CreatedDate' => $currentDate,
                                'IsApproved' => '1',
                                'IsActive' => '1',
                                'IsMarkForDelete' => '0'
                            );
                            //for create new customer
                            $AgencyCRMLeadSysId = $this->_crmagencyleadaccountObj->addCustomer($userLeadArray);
                            $agencyuserArray = array(
                                //'AgencySysId' => $AgencySysId,
                                'AgencySysId' => $this->intLoggedinUserAgencySysId,
                                'AgencyCRMLeadSysId' => $AgencyCRMLeadSysId,
                                'CRMCustSysId' => $CRMCustSysId,
                                'EmailId' => $email,
                                'Title' => $salution ? $salution : 0,
                                'Logo' => '',
                                'IsfromSM' => '0',
                                'UserId' => '0',
                                'CitySysId' => '',
                                'StateOrZoneSysId' => 0,
                                'CountrySysId' => '',
                                'IsEmployee' => '0',
                                'Contacts' => $mobilenum ? $mobilenum : '',
                                'countrycode' => $countrycode ? $countrycode : '',
                                'JoinDate' => $currentDate,
                                'UserName' => $fname . '' . $lname,
                                'FirstName' => $fname ? $fname : '',
                                'LastName' => $lname ? $lname : '',
                                'Relation' => '',
                                'PassportNo' => '',
                                'PassportExpiry' => '',
                                'DOB' => '',
                                'MarriageAnniversary' => '',
                                'CreatedByUserSysId' => $userSysId,
                                'RegisterDate' => $currentDate,
                                'UpdateDate' => $currentDate,
                                'IsApproved' => '0',
                                'IsActive' => '1',
                                'IsMarkForDelete' => '0',
                                'IsB2BAgent' => $IsB2BAgent
                            );
                            ### Insert Record in to Agency Table as well ########
                            $CustomerSysId = $this->_agencycustomerObj->addAgencyCustomer($agencyuserArray);
                        }
                    }
                    //#end of add b2b customer

                    $url = $this->siteUrl . "login";
                    $emailId = $getData['emailId'];

                    //Mail code to send login link to staff  
//                    $message = "Dear " . ucfirst($getData['first_name']) . ", <br><br>";
//                    $message .= "Staff login details:<br><br>";
//                    $message .= "Email Id/ Username: $emailId <br>";
//                    $message .= "Password: $oRandStrPass <br>";
//                    $message .= "Please <a href=" . $url . ">Click Here</a> to login your account. <br><br>";
//                    $message .= "Thanks,<br>";
//                    $message .= $this->fromName;
                    $params = array('agentName' => ucfirst($getData['first_name']), 'emailId' => $emailId, 'url' => $url, 'password' => $oRandStrPass);

                    #Set subject
                    $subject = 'Staff Login Details for ' . SITE_NAME;
                    $html = new Zend_View();
                    $html->setScriptPath(APPLICATION_PATH . '/views/emails/');
                    $html->assign($params);
                    $bodyText = $html->render('agent_login.phtml');

                    $emailData11 = array('fromEmail' => $this->fromEmail, 'fromName' => $this->fromName, 'subject' => $subject, 'to' => array($emailId), 'bodyHtml' => $bodyText, 'bodyText' => '');
                    try {
                        $arrEmailStatisticsType = array_keys(unserialize(ARR_EMAIL_STATISTICS_TYPE));
                        $arrEmailStatistics = array(
                            "TPSysId" => 0,
                            "TypeSysId" => 1, // 1 For Email 2 For SMS
                            "AgencySysId" => $AgencySysId,
                            "AgentSysId" => $userSysId,
                            "Title" => $bodyText,
                            "Source" => $arrEmailStatisticsType[2], // 1 For misc
                            "Status" => 0,
                            "RefSysId" => "",
                            "RefSysStatus" => "",
                            "CreateDate" => date('Y-m-d H:i:s')
                        );
                        if ($IsB2BAgent == 0) {
                            $this->mailSentByElastice($emailData11, $arrEmailStatistics, 1, $CustomerSysId);
                        }
                        //echo 1;exit;
                    } catch (Exception $err) {
                        //echo 2;exit;
                    }

//                    $mailConfig = array(
//                        'ssl' => 'ssl',
//                        'auth' => 'login',
//                        'port' => $this->smtpPort,
//                        'username' => $this->smtpUserName,
//                        'password' => $this->smtpPassword
//                    );
//
//                    $transport = new Zend_Mail_Transport_Smtp($this->smtpHost, $mailConfig);
//
//                    $mail = new Zend_Mail("iso-8859-1");
//                    $mail->addTo($emailId)
//                            ->addBcc('pooja@catpl.co.in')
//                            ->setSubject($subject)
//                            ->setBodyHtml($bodyText)
//                            ->setFrom($this->fromEmail, $this->fromName);
//
//                    try {
//                        $mail->send($transport);
//                    } catch (Exception $err) {
//                        print_r($err, true);
//                    }
                }

                $json = array('result' => 1, 'id' => base64_encode($userSysId));
                echo json_encode($json);
                exit;
//                echo 1;
//                exit;
            } else {
                echo json_encode(array('result' => 2));
                exit;
            }
        }
    }

    /*
     * emailExistsAction(); is used to check email id of user is exists in db or not
     * Created By- Pooja
     * Created on- 05 July 2016
     */

    public function emailExistsAction() {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        $emailId = $this->getRequest()->getParam('emailId');
        $StaffUserId = base64_decode($this->getRequest()->getParam('StaffUserId'));
        $B2BAgencyId = (NULL != $this->getRequest()->getParam('B2BAgencyId')) ? base64_decode($this->getRequest()->getParam('B2BAgencyId')) : '';

        $IsB2BAgent = (!empty($this->getRequest()->getParam('IsB2BAgent')) && ($this->getRequest()->getParam('IsB2BAgent') == 'true')) ? 1 : 0;
        if ($B2BAgencyId) {
            $IsB2BAgent = 1;
        }
        $AgencySysId = NULL;
        if ($IsB2BAgent == 1) {
            $AgencySysId = $this->intLoggedinUserAgencySysId;
        }
        $objStaff = new Travel_Model_TblAgencyStaff();
        if ($objStaff->isUserEmailExists(trim($emailId), $StaffUserId, $AgencySysId, $IsB2BAgent)) {
            // echo true;
            echo json_encode(false);
        } else {
            echo json_encode(true);
        }
    }

    /*
     * saveStaffAddressAction(); is used add/update user's address and pic
     * Created By- Pooja
     * Created on- 05 July 2016
     */

    public function saveStaffAddressAction() {
        //disable layout
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        if ($this->getRequest()->isXmlHttpRequest()) {
            $getData = $this->getRequest()->getParams();
            //$_SESSION['StaffAddress'] = $getData;

            $objStaff = new Travel_Model_TblAgencyStaff();

            $userSysId = base64_decode($getData['id']);
            $userData = $objStaff->getUserDataByUserId($userSysId);
            //print_r(@$_FILES);


            /* Upload Photo ID Proof */
            if (@$_FILES['file']) {
                $folder = USER_FILE_UPLOAD_PATH . 'agency/' . $this->intLoggedinUserAgencySysId . "/";

                $tmpFilePath = $_FILES['file']['tmp_name'];
                //Make sure we have a filepath
                $fileName = $_FILES['file']['name'];
                $ext = pathinfo($fileName, PATHINFO_EXTENSION);
                if (!in_array($ext, unserialize(IMAGE_EXTENSIONS))) {
                    echo json_encode(array('result' => 4));  //check extension of file 
                    exit;
                }
//            if (@$userData['UserPicPath']) {
                @unlink($folder . @$userData['UserPicPath']);
//            }
                $newFileName = 'photo_id_' . $userSysId . '_' . rand(0, 99);

                $newFileName = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName, $newFileName, $tmpFilePath, $folder);
//            echo $newFileName;
            }
            if (@$userSysId) { // update user's address
                $staffAddressData = array();
//                $date = new Zend_Date();
                $currentDate = date('Y-m-d H:i:s');
                $staffAddressData['UpdateDate'] = $currentDate;

                if (@$getData['staffAddress'] == '' || @$getData['postCode'] == '') {
                    echo json_encode(array('result' => 5));  // check for empty fields
                    exit;
                }
                $countryId = $getData['staff_country_id'];
                $cityId = $getData['staff_city_id'];
                $countryTitle = $getData['staffCountry'];
                $cityTitle = $getData['staffCity'];

                $objLocation = new Travel_Model_TblLocation();
                // save country to data base if not exists and get country id
                if (empty(trim($countryId))) {
                    $countryId = $objLocation->addCountry($countryTitle, $currentDate);
                }
                // save City to data base if not exists and get city id
                if (empty(trim($cityId))) {
                    $cityId = $objLocation->addCity($cityTitle, $countryId, $countryTitle, $currentDate);
                }

                $countryId ? ($staffAddressData['CountrySysId'] = $this->sanitize_data($countryId)) : '';
                $cityId ? ($staffAddressData['CitySysId'] = $this->sanitize_data($cityId)) : '';
                $getData['postCode'] ? ($staffAddressData['PinCode'] = $this->sanitize_data($getData['postCode'])) : '';
                $getData['staffAddress'] ? ($staffAddressData['Address'] = $this->sanitize_data_address($getData['staffAddress'])) : '';
                @$newFileName ? ($staffAddressData['UserPicPath'] = $this->sanitize_data($newFileName)) : '';
                $objStaff->editUserDetails($staffAddressData, $userSysId); //update Agency User

                echo json_encode(array('result' => 3, 'id' => base64_encode($userSysId)));
                exit;
            }
        }
    }

    /*
     * saveStaffMoreInformationAction(); is used add/update user's more information
     * Created By- Pooja
     * Created on- 06 July 2016
     */

    public function saveStaffMoreInformationAction() {
        //disable layout
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        if ($this->getRequest()->isXmlHttpRequest()) {
            $getData = $this->getRequest()->getParams();
            //$_SESSION['StaffMoreInformation'] = $getData;

            $objStaff = new Travel_Model_TblAgencyStaff();
            $userSysId = base64_decode($getData['id']);

            if (@$userSysId) { // update user's address
                $staffMoreInfoData = array();
//                $date = new Zend_Date();
                $currentDate = date('Y-m-d H:i:s');
                $staffMoreInfoData['UpdateDate'] = $currentDate;

                if (@$getData['mobilePhone'] == '') {
                    echo json_encode(array('result' => 5));  // check for empty fields
                    exit;
                }

                $getData['officePhone'] ? ($staffMoreInfoData['ContactNo2'] = $this->sanitize_data($getData['officePhone'])) : '';
                $getData['mobilePhone'] ? ($staffMoreInfoData['ContactNo1'] = $this->sanitize_data($getData['mobilePhone'])) : '';
                $getData['countrycode'] ? ($staffMoreInfoData['countrycode'] = $this->sanitize_data($getData['countrycode'])) : '';
                $getData['homePhone'] ? ($staffMoreInfoData['HomePhone'] = $this->sanitize_data($getData['homePhone'])) : '';
                $getData['fax'] ? ($staffMoreInfoData['Fax'] = $this->sanitize_data($getData['fax'])) : '';
                $getData['otherEmail'] ? ($staffMoreInfoData['OtherEmail'] = $this->sanitize_data($getData['otherEmail'])) : '';
                $getData['secondaryEmail'] ? ($staffMoreInfoData['SecondaryEmail'] = $this->sanitize_data($getData['secondaryEmail'])) : '';
                $getData['secondaryPhone'] ? ($staffMoreInfoData['SecondaryPhone'] = $this->sanitize_data($getData['secondaryPhone'])) : '';
                $getData['language'] ? ($staffMoreInfoData['SpeakingLangSysId'] = $this->sanitize_data($getData['language'])) : '';
                $getData['details'] ? ($staffMoreInfoData['UserDetails'] = $this->sanitize_data($getData['details'])) : '';
                $objStaff->editUserDetails($staffMoreInfoData, $userSysId); //update Agency User
                if ($getData['reportsTo'] && $getData['reportsTo'] > 0) {
                    $deptMappingArr = array(
                        'ReportingToSysId' => $this->sanitize_data($getData['reportsTo']),
                        'IsMarkForDelete' => 0,
                        'IsActive' => 1,
                    );
                } else {
                    $deptMappingArr = array(
                        'IsMarkForDelete' => 1,
                        'IsActive' => 0,
                    );
                }
                $objStaff->editDeptUserMapping($deptMappingArr, $userSysId); // update reports to in department mapping

                echo json_encode(array('result' => 3, 'id' => base64_encode($userSysId)));
                exit;
            }
        }
    }

    public function saveStaffPermissionAction() {
        //disable layout
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        //if ($this->getRequest()->isXmlHttpRequest()) {
        $getData = $this->getRequest()->getParams();
        //echo '<pre>';print_r($getData);die;
        $mainMenuTitle = explode(',', $getData['selectedmainMenuName']);
        $subMenuTitle = explode(',', $getData['selectedsubMenuName']);
        $mainMenuVal = explode(',', $getData['selectedmainMenu']);
        $subMenuVal = explode(',', $getData['selectedsubMenu']);

        $userContentVal = explode(',', $getData['selecteduserContent']);
        $userContentTitle = explode(',', $getData['selecteduserContentName']);
//            $mainMenuUrl = explode(',',$getData['selectedmainMenuUrl']);
//            $subMenuUrl = explode(',',$getData['selectedsubMenuUrl']);
        //echo '<pre>';print_r($subMenuVal);
        //echo '<pre>';print_r($subMenuTitle);die;
//            if($mainMenuVal){ $suArr = [];
//                foreach ($mainMenuVal as $key => $value) {
//                    echo $value.'===';
//                    
//                    foreach ($subMenuVal as $valsub) {
//                        $suArr[$value] = $valsub;
//                    }
//                     echo '<pre>';print_r($suArr);
//                    //echo $subMenuVal[];
//                }
//            }
        //die;
        //$_SESSION['StaffMoreInformation'] = $getData;
        //echo '<pre>';print_r($nivigationToparray);die;
        $objStaff = new Travel_Model_TblAgencyStaff();
        $userSysId = base64_decode($getData['id']);

        if (@$userSysId) { // update user's address
            $staffMoreInfoData = array();
//            $date = new Zend_Date();
            $currentDate = date('Y-m-d H:i:s');
            $staffMoreInfoData['UpdateDate'] = $currentDate;

            $objStaff->editUserDetails($staffMoreInfoData, $userSysId); //update Agency User
            $objStaff->permission_delete(array('AgentSysId=?' => $userSysId));
            $objStaff->permission_con_delete(array('AgentSysId=?' => $userSysId));

            foreach ($mainMenuVal as $k => $val) {
                $deptMappingArr = array(
                    'AgencySysId' => $this->intLoggedinUserAgencySysId,
                    'AgentSysId' => $userSysId,
                    'Parent_Id' => 0,
                    'Title' => $mainMenuTitle[$k],
                    'val' => $val,
                    'url' => '',
                    'CreateDate' => $currentDate,
                    'UpdateDate' => $currentDate,
                    'IsActive' => 1,
                );
                $insertId = $objStaff->addPermissionMapping($deptMappingArr);
            }
            foreach ($subMenuVal as $key => $valSet) {
                $deptMappingArr = array(
                    'AgencySysId' => $this->intLoggedinUserAgencySysId,
                    'AgentSysId' => $userSysId,
                    'Parent_Id' => ($key + 1),
                    'Title' => $subMenuTitle[$key],
                    'val' => $valSet,
                    'url' => '',
                    'CreateDate' => $currentDate,
                    'UpdateDate' => $currentDate,
                    'IsActive' => 1,
                );
                $insertId = $objStaff->addPermissionMapping($deptMappingArr);
            }

            if (!empty($userContentVal[0])) {
                foreach ($userContentVal as $k => $val) {
                    $dataArr = array(
                        'AgencySysId' => $this->intLoggedinUserAgencySysId,
                        'AgentSysId' => $userSysId,
                        'Title' => $userContentTitle[$k],
                        'val' => $val,
                        'CreateDate' => $currentDate,
                        'UpdateDate' => $currentDate,
                        'IsActive' => 1,
                    );
                    $insertId = $objStaff->addPermissionContent($dataArr);
                }
            }
            echo json_encode(array('result' => 3, 'id' => base64_encode($userSysId)));
            exit;
        }
        // }
    }

    public function sanitize_data($input_data) {
        $searchArr = array("document", "write", "alert", "%", "$", ";", "+", "|", "#", "<", ">", ")", "(", "'", "\'", ",", "AND", "JAVASCRIPT");
        $input_data = str_replace("script", "", $input_data);
        $input_data = str_replace("iframe", "", $input_data);
        $input_data = str_replace($searchArr, "", $input_data);

        return htmlentities(stripslashes(trim($input_data)), ENT_QUOTES);
    }

    public function sanitize_data_address($input_data) {
        $searchArr = array("document", "write", "alert", "%", "$", ";", "+", "|", "#", "<", ">", "'", "\'", "AND", "JAVASCRIPT");
        $input_data = str_replace("script", "", $input_data);
        $input_data = str_replace("iframe", "", $input_data);
        $input_data = str_replace($searchArr, "", $input_data);

        return htmlentities(stripslashes(trim($input_data)), ENT_QUOTES);
    }

    /*
     * saveStaffSignatureAction(); is used add/update user's more information
     * Created By- Pooja
     * Created on- 08 July 2016
     */

    public function saveStaffSignatureAction() {

        //disable layout
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        if ($this->getRequest()->isXmlHttpRequest()) {
            $getData = $this->getRequest()->getParams();
            //$_SESSION['StaffSignature'] = $getData;
            $objStaff = new Travel_Model_TblAgencyStaff();
            //echo '<pre>';
            //print_r($getData);die;
            $userSysId = base64_decode($getData['id']);

            if (@$userSysId) { // update user's address
                $staffSignData = array();
//                $date = new Zend_Date();
                $currentDate = date('Y-m-d H:i:s');
                $staffSignData['UpdateDate'] = $currentDate;

                if (@$getData['signature'] == '') {
                    echo json_encode(array('result' => 2));  // check for empty fields
                    exit;
                }

                $staffSignData['signature'] = @$getData['signature'] ? ($getData['signature']) : '';
                $objStaff->editUserDetails($staffSignData, $userSysId); //update Agency User
                echo json_encode(array('result' => 3, 'id' => base64_encode($userSysId)));
                exit;
            }
        }
    }

    public function permissionControlAction() {

        //set layout
        $this->_helper->layout->disableLayout();
        if ($this->getRequest()->getParams()) {
            $StaffUserId = base64_decode($this->getRequest()->getParam('StaffUserId'));
            $maid = base64_decode($this->getRequest()->getParam('maId'));

            $objStaff = new Travel_Model_TblAgencyStaff();
            $this->view->userData = $objStaff->getUserDataByUserId($StaffUserId);
            $PermissionMainMenuUserData = $objStaff->getUserPermissionMainMenu($StaffUserId);
            $PermissionUserData = $objStaff->getUserPermissionSubMenu($StaffUserId);
            $PerContUserData = $objStaff->getUserPermissionContent($StaffUserId);
            $MainMenufinalArr = [];
            $finalArr = [];
            $finalContentArr = [];
            if ($PermissionUserData) {
                foreach ($PermissionUserData as $key => $value) {
                    $finalArr[] = $value['val'];
                }
            }

            if ($PermissionMainMenuUserData) {
                foreach ($PermissionMainMenuUserData as $k => $val) {
                    $MainMenufinalArr[] = $val['val'];
                }
            }

            if ($PerContUserData) {
                foreach ($PerContUserData as $k => $val) {
                    $finalContentArr[] = $val['val'];
                }
            }

            $this->view->PermissionMainMenuUserData = $MainMenufinalArr;
            $this->view->PermissionUserData = $finalArr;
            $this->view->ContentArrUserData = $finalContentArr;
            //echo "<pre>";print_r($PermissionMainMenuUserData);
            //exit;
            $UserRole = $this->view->userData['UserRole'];
//            echo $StaffUserId; die;
        }
        $isActive = 1;
        $objStaff = new Travel_Model_TblAgencyStaff();
        $isB2BAgent = (isset($maid) && $maid > 0) ? 1 : 0;
        $AgencySysId = $this->intLoggedinUserAgencySysId;
        //$this->view->AgencyStaffList = $objStaff->getAgencyStaffListUserRole($isActive, @$StaffUserId,$AgencySysId,$isB2BAgent);
        $this->view->AgencyStaffList = $objStaff->getAgencyStaffListUserRolewithReport($isActive, @$StaffUserId, $AgencySysId, $isB2BAgent, $UserRole);
    }

    public function checkOpsAction() {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);
        $objStaff = new Travel_Model_TblAgencyStaff();
        $returnVal = 0;
        if ($this->getRequest()->isXmlHttpRequest()) {
            $id = (int) $this->getRequest()->getParam('id');
            $resultSet = $objStaff->checkOps($id);
            //alert
            if ($resultSet > 0) {
                $returnVal = 1;
            }
        }
        echo $returnVal;
        exit;
    }

    /**
     * Deactivate Staff Action. 
     */
    public function deactivateAction() {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        $objStaff = new Travel_Model_TblAgencyStaff();
        $staffId = $this->getRequest()->getParam('id');
        $B2BAgencySysId = (NULL != $this->getRequest()->getParam('aid')) ? $this->getRequest()->getParam('aid') : '';
        $isb2b = (NULL != $this->getRequest()->getParam('isb2b')) ? $this->getRequest()->getParam('isb2b') : '';
        $Agencylink = '';
        if ($B2BAgencySysId != '') {
            $Agencylink = 'index/aid/' . $B2BAgencySysId;
        }
        if ($isb2b == 1) {
            $B2BAgencySysId = base64_decode($B2BAgencySysId);
            $objStaff->setActiveDeactive(" AgencySysId=$B2BAgencySysId", "TB_Agency", 0);
            $objStaff->setActiveDeactive(" AgencySysId=$B2BAgencySysId", "TB_Agency_User", 0);
        }
        $isDeactive = $objStaff->setActiveDeactive(" UserSysId=$staffId", "TB_Agency_User", 0);
        $message = @$isDeactive ? "Staff deactivated successfully." : "Staff deactivation failed.";

        $this->_helper->flashMessenger->addMessage($message);

        if (@$isDeactive) {
            $this->_redirect('/staff/' . $Agencylink);
        }
    }

    /**
     * Activate Staff Action. 
     */
    public function activateAction() {
        $this->_helper->layout->disableLayout();
        $this->_helper->viewRenderer->setNoRender(true);

        $objStaff = new Travel_Model_TblAgencyStaff();
        $staffId = $this->getRequest()->getParam('id');
        $B2BAgencySysId = (NULL != $this->getRequest()->getParam('aid')) ? $this->getRequest()->getParam('aid') : '';
        $isb2b = (NULL != $this->getRequest()->getParam('isb2b')) ? $this->getRequest()->getParam('isb2b') : '';
        $Agencylink = '';
        if ($B2BAgencySysId != '') {
            $Agencylink = 'index/aid/' . $B2BAgencySysId;
        }
        if ($isb2b == 1) {
            $B2BAgencySysId = base64_decode($B2BAgencySysId);
            $objStaff->setActiveDeactive(" AgencySysId=$B2BAgencySysId", "TB_Agency", 1);
        }
        $isActive = $objStaff->setActiveDeactive(" UserSysId=$staffId", "TB_Agency_User", 1);
        $message = @$isActive ? "Staff activated successfully." : "Staff activation failed.";

        $this->_helper->flashMessenger->addMessage($message);

        if (@$isActive) {
            $this->_redirect('/staff/' . $Agencylink);
        }
    }

    public function autosuggestAgencyNameAction() {
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout();
        try {
            $arrResponse = array();
            if ($this->getRequest()->getParam("term") or $this->getRequest()->getParam("query")) {
                $query = $this->getRequest()->getParam("query") ? $this->getRequest()->getParam("query") : '';
                $AgencySysId = $this->getRequest()->getParam("AgencySysId") ? $this->getRequest()->getParam("AgencySysId") : $this->intLoggedinUserAgencySysId;
                //$this->intLoggedinUserAgencySysId
                $objStaff = new Travel_Model_TblAgencyStaff();
                $condAgency = "tb1.Title like '%" . $query . "%' or tb1.PrimaryContactName like '%" . $query . "%' or tb1.PrimaryEmail like '%" . $query . "%' or tb1.ContactInfo like '%" . $query . "%'";
                if (isset($AgencySysId) && !empty($AgencySysId)) {
                    //$condAgency .= "  AND tb1.MasterAgencySysId = " . $AgencySysId . " ";
                }
                $arrResponse = $objStaff->getAgencyAutoSuggest($condAgency, $AgencySysId);
            }
            echo json_encode($arrResponse);
            exit;
        } catch (Exception $e) {
            $response = array('success' => false, 'msg' => $e->getMessage());
            echo json_encode($response);
            exit;
        }
    }

    public function addB2bAgencyAction() {
        $id = $this->getRequest()->getParam('id');
        $this->view->isb2b = 1;
        $this->view->UserId = $id;
        $objStaff = new Travel_Model_TblAgencyStaff();
        $UserData = $objStaff->getUserDataByUserId(base64_decode($id));
    }

    public function agencyAction() {
        $objAgency = new Travel_Model_TblAgency();
        $MasterAgencySysId = $this->intLoggedinUserAgencySysId;
        $getData = $this->getRequest()->getPost();
        // $getData=$this->sanitizeData($getData);
        if ($getData) {
            $this->_HtmlPurifier = new Zend_Filter_HtmlPurifier();
            $getData = $this->_HtmlPurifier->filterArray($getData);
            $this->view->searchData = $getData;
        }
        $AgencyList = $objAgency->getB2BAgency($MasterAgencySysId, $getData);
        //print_r($AgencyList);die;
        $page = $this->_getParam('page', 1);
        $paginator = Zend_Paginator::factory($AgencyList);
        $paginator->setItemCountPerPage(GRID_PER_PAGE_RECORD_COUNT);
        $paginator->setCurrentPageNumber($page);
        $this->view->paginator = $paginator;
        $msg = $this->_getParam('msg');
        $this->view->msg = $msg;
        $this->view->controller = $this;
        $this->view->messages = $this->_helper->flashMessenger->getMessages();
    }

    public function autosuggestB2bAgentNameAction() {
        $this->_helper->viewRenderer->setNoRender(true);
        $this->_helper->layout->disableLayout();
        $sessionLogin_user = new Zend_Session_Namespace('sessionLogin_user');
        $AgencyType = $sessionLogin_user->agencyDetails['AgencyType'];
        try {
            $arrResponse = array();
            if ($this->getRequest()->getParam("term") or $this->getRequest()->getParam("query")) {
                $query = $this->getRequest()->getParam("query") ? $this->getRequest()->getParam("query") : '';
                $b2btype = $this->getRequest()->getParam("b2btype",1);
                $AgencySysId = $this->getRequest()->getParam("AgencySysId") ? $this->getRequest()->getParam("AgencySysId") : $this->intLoggedinUserAgencySysId;
                $objStaff = new Travel_Model_TblAgencyStaff();
                $condAgency = "tb6.Title like '%" . $query . "%' or tb6.PrimaryContactName like '%" . $query . "%' or tb6.PrimaryEmail like '%" . $query . "%' or tb6.ContactInfo like '%" . $query . "%' or tb1.EmailId like '%" . $query . "%' or tb1.FirstName like '%" . $query . "%' or tb1.LastName like '%" . $query . "%' ";
                $arrResponse = $objStaff->getB2BAgentAutoSuggest($condAgency, $AgencySysId,$AgencyType,$b2btype);
            }
            echo json_encode($arrResponse);
            exit;
        } catch (Exception $e) {
            $response = array('success' => false, 'msg' => $e->getMessage());
            echo json_encode($response);
            exit;
        }
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit