public function service()
 {
     $companyDealersManager = new CompanyDealersManager($this->config, $this->args);
     $userId = $companyDealersManager->secure($_REQUEST["user_id"]);
     $companyId = $this->sessionManager->getUser()->getId();
     if ($companyDealersManager->getByCompanyIdAndUserId($userId, $companyId)) {
         $companyDealersManager->removeUserFromCompany($userId, $companyId);
         $jsonArr = array('status' => "ok", "message" => "Dealer successfully removed from your company!");
         echo json_encode($jsonArr);
         return true;
     } else {
         $jsonArr = array('status' => "err", "errText" => "System Error: Dealer dosn't exist in your list!");
         echo json_encode($jsonArr);
         return false;
     }
 }
 /**
  * Returns an singleton instance of this class
  *
  * @param object $config
  * @param object $args
  * @return
  */
 public static function getInstance($config, $args)
 {
     if (self::$instance == null) {
         self::$instance = new CompanyDealersManager($config, $args);
     }
     return self::$instance;
 }
예제 #3
0
 public function load()
 {
     $companyManager = CompanyManager::getInstance($this->config, $this->args);
     $adminManager = AdminManager::getInstance($this->config, $this->args);
     $userManager = UserManager::getInstance($this->config, $this->args);
     $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
     $allAdmins = $adminManager->selectAll();
     if ($this->getUserLevel() === UserGroups::$COMPANY) {
         $allCompanies = $companyManager->getAllCompanies();
         $companyDealersJoindWithUsersFullInfo = $companyDealersManager->getCompanyDealersJoindWithUsersFullInfo($this->getUserId());
         $this->addParam('allCompanies', $allCompanies);
         $this->addParam('allDealers', $companyDealersJoindWithUsersFullInfo);
         $this->addParam('allAdmins', $allAdmins);
     }
     if ($this->getUserLevel() === UserGroups::$SERVICE_COMPANY) {
         $allCompanies = $companyManager->getAllCompanies();
         $this->addParam('allCompanies', $allCompanies);
         $this->addParam('allAdmins', $allAdmins);
     }
     if ($this->getUserLevel() === UserGroups::$ADMIN) {
         $allCompanies = $companyManager->getAllCompanies(true, true);
         $allUsers = $userManager->selectAll();
         $this->addParam('allCompanies', $allCompanies);
         $this->addParam('allUsers', $allUsers);
         $this->addParam('allAdmins', $allAdmins);
     }
     if ($this->getUserLevel() === UserGroups::$USER) {
         $allCompanies = $companyManager->getAllCompanies();
         $allUsers = $userManager->selectAll();
         $dealerCompanies = $companyManager->getUserCompaniesJoindWithFullInfo($this->getUserId());
         $this->addParam('allCompanies', $dealerCompanies);
         //$this->addParam('allUsers', $allUsers);
         $this->addParam('allAdmins', $allAdmins);
     }
 }
예제 #4
0
 public function load()
 {
     $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
     $companyId = $this->sessionManager->getUser()->getId();
     $dealers = $companyDealersManager->getCompanyDealersJoindWithUsersFullInfo($companyId);
     $this->addParam('dealers', $dealers);
 }
예제 #5
0
 /**
  * Initializes DB mappers
  *
  * @param object $config
  * @param object $args
  * @return
  */
 function __construct($config, $args)
 {
     $this->mapper = CompanyMapper::getInstance();
     $this->config = $config;
     $this->args = $args;
     $this->companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
     $this->requestHistoryManager = RequestHistoryManager::getInstance($this->config, $this->args);
     $this->companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
 }
예제 #6
0
 public function service()
 {
     $userManager = new UserManager($this->config, $this->args);
     $companyManager = new CompanyManager($this->config, $this->args);
     $companyDealersManager = new CompanyDealersManager($this->config, $this->args);
     $access_key = $userManager->secure($_REQUEST["access_key"]);
     $company = $companyManager->getCompanyByAccessKey($access_key);
     if ($company) {
         $userId = $this->getUserId();
         $companyId = $company->getId();
         if (!$companyDealersManager->getByCompanyIdAndUserId($userId, $companyId)) {
             $customer = $this->getCustomer();
             $customerEmail = $customer->getEmail();
             $customerCartManager = CustomerCartManager::getInstance($this->args, $this->config);
             $items = $customerCartManager->getCustomerItemsByCompanyId($customerEmail, $companyId);
             $bundlesIds = $customerCartManager->getCustomerBundlesIdsByCompanyId($customerEmail, $companyId);
             $customerCartManager->deleteCompanyRelatedItemsFromCustomerCart($customerEmail, $companyId);
             $companyDealersManager->addUserToCompany($userId, $companyId);
             $message = $this->getPhrase(437) . ' ' . $company->getName() . "'! \n";
             if (!empty($items)) {
                 $message .= $this->getPhrase(436) . "'\n";
             }
             if (!empty($bundlesIds)) {
                 $message .= $this->getPhrase(435);
             }
             $jsonArr = array('status' => "ok", "message" => $message);
             echo json_encode($jsonArr);
             return true;
         } else {
             $jsonArr = array('status' => "err", "errText" => "You already have '" . $company->getName() . "' company in your list!");
             echo json_encode($jsonArr);
             return false;
         }
     } else {
         $jsonArr = array('status' => "err", "errText" => "Access key incorrect!");
         echo json_encode($jsonArr);
         return false;
     }
 }
예제 #7
0
 public function load()
 {
     $userManager = UserManager::getInstance($this->config, $this->args);
     $allUsersDtos = $userManager->selectAll();
     $this->addParam("users", $allUsersDtos);
     $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
     $serviceCompanyDealersManager = ServiceCompanyDealersManager::getInstance($this->config, $this->args);
     $allCompanyDealers = $companyDealersManager->getAllUsersCompaniesFull();
     $userCompanies = $this->getUserCompaniesArray($allCompanyDealers);
     $allServiceCompanyDealers = $serviceCompanyDealersManager->getAllUsersCompaniesFull();
     $userServiceCompanies = $this->getUserCompaniesArray($allServiceCompanyDealers);
     $this->addParam('userCompanies', $userCompanies);
     $this->addParam('userServiceCompanies', $userServiceCompanies);
     $this->addParam('visible_fields_names', array('id', 'email', 'name', 'lastName', 'phones', 'password', 'registeredDate', 'lastSmsValidationCode', 'vip'));
 }
 public function load()
 {
     $loadPage = 0;
     if (isset($_REQUEST['load_page'])) {
         $loadPage = $_REQUEST['load_page'];
     }
     if ($loadPage == 1) {
         $this->addParam("page_loaded", 1);
         $userManager = UserManager::getInstance($this->config, $this->args);
         $allUsersDtos = $userManager->selectAll();
         $this->addParam("users", $allUsersDtos);
     } else {
         $this->addParam("page_loaded", 0);
     }
     $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
     $serviceCompanyDealersManager = ServiceCompanyDealersManager::getInstance($this->config, $this->args);
     $allCompanyDealers = $companyDealersManager->getAllUsersCompaniesFull();
     $userCompanies = $this->getUserCompaniesArray($allCompanyDealers);
     $allServiceCompanyDealers = $serviceCompanyDealersManager->getAllUsersCompaniesFull();
     $userServiceCompanies = $this->getUserCompaniesArray($allServiceCompanyDealers);
     $this->addParam('userCompanies', $userCompanies);
     $this->addParam('userServiceCompanies', $userServiceCompanies);
 }
예제 #9
0
 public function deleteUserAndDependencies($id)
 {
     $userDto = $this->selectByPK($id);
     if ($userDto) {
         $email = $userDto->getEmail();
         $this->deleteByPK($id);
         $userSubUsersManager = UserSubUsersManager::getInstance($this->config, $this->args);
         $userSubUsersManager->deleteByField('user_id', $id);
         $userPendingSubUsersManager = UserPendingSubUsersManager::getInstance($this->config, $this->args);
         $userPendingSubUsersManager->deleteByField('user_id', $id);
         require_once CLASSES_PATH . "/managers/CustomerCartManager.class.php";
         $customerCartManager = CustomerCartManager::getInstance($this->config, $this->args);
         $customerCartManager->deleteByField('email', $email);
         require_once CLASSES_PATH . "/managers/CustomerLocalEmailsManager.class.php";
         $customerLocalEmailsManager = CustomerLocalEmailsManager::getInstance($this->config, $this->args);
         $customerLocalEmailsManager->deleteByField('customer_email', $email);
         require_once CLASSES_PATH . "/managers/CompanyDealersManager.class.php";
         $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
         $companyDealersManager->deleteByField('user_id', $id);
     }
 }
예제 #10
0
 public function service()
 {
     //todo check if user have access to given company
     $customer = $this->sessionManager->getUser();
     $userLevel = $customer->getLevel();
     $userId = $customer->getId();
     $companyManager = CompanyManager::getInstance($this->config, $this->args);
     $serviceCompanyManager = ServiceCompanyManager::getInstance($this->config, $this->args);
     if ($this->args[0] == "last_price") {
         $companyId = $this->args[1];
         if ($userLevel == UserGroups::$USER) {
             $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
             $dto = $companyDealersManager->getByCompanyIdAndUserId($userId, $companyId);
             if (!isset($dto)) {
                 return false;
             }
         }
         $company = $companyManager->selectByPK($companyId);
         assert($company);
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($companyId);
         if (!empty($companyLastPrices)) {
             if (count($companyLastPrices) === 1) {
                 $pricePath = DATA_DIR . "/companies_prices/" . $companyId . '/' . $companyLastPrices[0]->getFileName() . '.' . $companyLastPrices[0]->getFileExt();
                 if (file_exists($pricePath)) {
                     $companiesPriceListManager->downloadFile($pricePath, $company->getShortName() . "_" . $companyLastPrices[0]->getFileName());
                 } else {
                     echo "file not exists!";
                 }
             } else {
                 $filesPaths = array();
                 foreach ($companyLastPrices as $key => $clp) {
                     $fileName = $clp->getFileName() . '.' . $clp->getFileExt();
                     $filesPaths[] = array(DATA_DIR . "/companies_prices/" . $company->getId() . '/' . $fileName, $company->getShortName() . '_' . ($key + 1) . '_' . $fileName);
                 }
                 $uid = uniqid();
                 $this->createZip($filesPaths, DATA_DIR . "/temp/" . $uid . '.zip');
                 $companiesPriceListManager->downloadFile(DATA_DIR . "/temp/" . $uid . '.zip', $company->getShortName() . '_price');
                 unlink(DATA_DIR . "/temp/" . $uid . '.zip');
             }
         } else {
             echo "file not exists!";
         }
     }
     if ($this->args[0] == "service_last_price") {
         $companyId = $this->args[1];
         if ($userLevel == UserGroups::$USER) {
             $serviceCompanyDealersManager = ServiceCompanyDealersManager::getInstance($this->config, $this->args);
             $dto = $serviceCompanyDealersManager->getByCompanyIdAndUserId($userId, $companyId);
             if (!isset($dto)) {
                 return false;
             }
         }
         $company = $serviceCompanyManager->selectByPK($companyId);
         assert($company);
         $companiesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
         $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($companyId);
         if (!empty($companyLastPrices)) {
             if (count($companyLastPrices) === 1) {
                 $pricePath = DATA_DIR . "/service_companies_prices/" . $companyId . '/' . $companyLastPrices[0]->getFileName() . '.' . $companyLastPrices[0]->getFileExt();
                 if (file_exists($pricePath)) {
                     $companiesPriceListManager->downloadFile($pricePath, $company->getShortName() . "_" . $companyLastPrices[0]->getFileName());
                 } else {
                     echo "file not exists!";
                 }
             } else {
                 $filesPaths = array();
                 foreach ($companyLastPrices as $key => $clp) {
                     $fileName = $clp->getFileName() . '.' . $clp->getFileExt();
                     $filesPaths[] = array(DATA_DIR . "/service_companies_prices/" . $company->getId() . '/' . $fileName, $company->getShortName() . '_' . ($key + 1) . '_' . $fileName);
                 }
                 $uid = uniqid();
                 $this->createZip($filesPaths, DATA_DIR . "/temp/" . $uid . '.zip');
                 $companiesPriceListManager->downloadFile(DATA_DIR . "/temp/" . $uid . '.zip', $company->getShortName() . '_price');
                 unlink(DATA_DIR . "/temp/" . $uid . '.zip');
             }
         } else {
             echo "file not exists!";
         }
     }
     if ($this->args[0] == "zipped_price") {
         $zippedPriceId = $this->args[1];
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         $price = $companiesPriceListManager->selectByPK($zippedPriceId);
         $company_id = $price->getCompanyId();
         if ($userLevel == UserGroups::$USER) {
             $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
             $dto = $companyDealersManager->getByCompanyIdAndUserId($userId, $company_id);
             if (!isset($dto)) {
                 return false;
             }
         }
         $company = $companyManager->selectByPK($company_id);
         assert($company);
         if ($price) {
             $pricePath = DATA_DIR . "/companies_prices/" . $price->getCompanyId() . '/' . $price->getFileName() . '.' . $price->getFileExt();
             if (file_exists($pricePath)) {
                 $companiesPriceListManager->downloadFile($pricePath, $company->getShortName() . "_" . $price->getFileName());
             } else {
                 echo "file not exists!";
             }
         } else {
             echo "file not exists!";
         }
     }
     if ($this->args[0] == "zipped_price_unzipped") {
         $zippedPriceId = $this->args[1];
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         $price = $companiesPriceListManager->selectByPK($zippedPriceId);
         $company_id = $price->getCompanyId();
         if ($userLevel == UserGroups::$USER) {
             $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
             $dto = $companyDealersManager->getByCompanyIdAndUserId($userId, $company_id);
             if (!isset($dto)) {
                 return false;
             }
         }
         $company = $companyManager->selectByPK($company_id);
         assert($company);
         if ($price) {
             $pricePath = DATA_DIR . "/companies_prices/" . $price->getCompanyId() . '/' . $price->getFileName() . '.' . $price->getFileExt();
             if (file_exists($pricePath)) {
                 $unzipPriceFile = $companiesPriceListManager->unzipFile($pricePath);
                 if (count($unzipPriceFile) === 1) {
                     $companiesPriceListManager->downloadFile($unzipPriceFile[0], $company->getShortName() . "_" . $price->getFileName());
                 } else {
                     $companiesPriceListManager->downloadFile($pricePath, $company->getShortName() . "_" . $price->getFileName());
                 }
             } else {
                 echo "file not exists!";
             }
         } else {
             echo "file not exists!";
         }
     }
     if ($this->args[0] == "service_zipped_price_unzipped") {
         $zippedPriceId = $this->args[1];
         $companiesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
         $price = $companiesPriceListManager->selectByPK($zippedPriceId);
         $company_id = $price->getServiceCompanyId();
         if ($userLevel == UserGroups::$USER) {
             $serviceCompanyDealersManager = ServiceCompanyDealersManager::getInstance($this->config, $this->args);
             $dto = $serviceCompanyDealersManager->getByCompanyIdAndUserId($userId, $company_id);
             if (!isset($dto)) {
                 return false;
             }
         }
         $company = $serviceCompanyManager->selectByPK($company_id);
         assert($company);
         if ($price) {
             $pricePath = DATA_DIR . "/service_companies_prices/" . $price->getServiceCompanyId() . '/' . $price->getFileName() . '.' . $price->getFileExt();
             if (file_exists($pricePath)) {
                 $unzipPriceFile = $companiesPriceListManager->unzipFile($pricePath);
                 if (count($unzipPriceFile) === 1) {
                     $companiesPriceListManager->downloadFile($unzipPriceFile[0], $company->getShortName() . "_" . $price->getFileName());
                 } else {
                     $companiesPriceListManager->downloadFile($pricePath, $company->getShortName() . "_" . $price->getFileName());
                 }
             } else {
                 echo "file not exists!";
             }
         } else {
             echo "file not exists!";
         }
     }
     if ($this->args[0] == "all_zipped_prices") {
         $companiesList = array();
         if ($userLevel == UserGroups::$COMPANY) {
             $companiesList = $companyManager->getAllCompaniesByPriceHours();
         }
         if ($userLevel == UserGroups::$USER) {
             $companiesList = $companyManager->getUserCompaniesJoindWithFullInfo($userId);
         }
         if ($userLevel == UserGroups::$ADMIN) {
             $companiesList = $companyManager->getAllCompaniesByPriceHours(0, "", true, true);
         }
         $filesPaths = array();
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         foreach ($companiesList as $company) {
             $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($company->getId());
             foreach ($companyLastPrices as $key => $companyLastPrice) {
                 $fileName = $companyLastPrice->getFileName() . '.' . $companyLastPrice->getFileExt();
                 $filesPaths[] = array(DATA_DIR . "/companies_prices/" . $company->getId() . '/' . $fileName, $company->getShortName() . '_' . $fileName . '_' . ($key + 1));
             }
         }
         $uid = uniqid();
         $this->createZip($filesPaths, DATA_DIR . "/temp/" . $uid . '.zip');
         $companiesPriceListManager->downloadFile(DATA_DIR . "/temp/" . $uid . '.zip', 'all');
         unlink(DATA_DIR . "/temp/" . $uid . '.zip');
     }
 }
 public function addCustomerMessagesAfterLoginByPreviousPing($custDto, $userLevel, $previousPing)
 {
     if ($userLevel === UserGroups::$GUEST) {
         return false;
     }
     $custEmail = $custDto->getEmail();
     $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
     $userCompaniesIdsArray = array();
     if ($userLevel === UserGroups::$USER) {
         $userCompaniesIdsArray = $companyDealersManager->getUserCompaniesIdsArray($custDto->getId());
     }
     if ($userLevel === UserGroups::$COMPANY || $userLevel === UserGroups::$ADMIN || !empty($userCompaniesIdsArray)) {
         //new prices after last ping
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         $allPricesAfterTime = $companiesPriceListManager->getAllPricesAfterTime($previousPing, $userCompaniesIdsArray);
         if (!empty($allPricesAfterTime)) {
             $pre = HTTP_PROTOCOL . HTTP_HOST;
             $massage = '';
             foreach ($allPricesAfterTime as $dto) {
                 $companyName = $dto->getCompanyName() . ' (`558`: ' . $dto->getUploadDateTime() . ')';
                 $companyId = $dto->getCompanyId();
                 $pricePath = HTTP_PROTOCOL . HTTP_HOST . '/price/last_price/' . $companyId;
                 $massage .= '<div><a href="' . $pricePath . '"><img src="' . $pre . '/images/small_logo/' . $companyId . '" style="vertical-align: middle;" /> ' . $companyName . '</a></div>';
             }
             $this->addCustomerMessage($custEmail, '540', $massage, 1, 'attention');
         }
     }
     //new added dealers messages for (company only)
     if ($userLevel === UserGroups::$COMPANY || $userLevel === UserGroups::$ADMIN) {
         $dealersAfterGivenDatetime = $companyDealersManager->getAfterGivenDatetime($userLevel === UserGroups::$ADMIN ? 0 : intval($custDto->getId()), $previousPing);
         if (!empty($dealersAfterGivenDatetime)) {
             $this->addCustomerMessage($custEmail, '543', '`541` ' . count($dealersAfterGivenDatetime) . '`542`', 1, 'attention');
         }
     }
     //alert to admin if dollar rate doeasn't match to config rate
     if ($userLevel === UserGroups::$ADMIN) {
         $cbaRatesManager = CbaRatesManager::getInstance($this->config, $this->args);
         $latestUSDExchange = $cbaRatesManager->getLatestUSDExchange();
         $us_dollar_exchange = floatval($this->getCmsVar('us_dollar_exchange'));
         $us_dollar_exchange_down = floatval($this->getCmsVar('us_dollar_exchange_down'));
         $pcstoreAverageUSDExchange = ($us_dollar_exchange + $us_dollar_exchange_down) / 2;
         $maxAllowedDollarDifferenceParcent = floatval($this->getCmsVar('admin_alert_if_cba_dollar_rate_is_more_than_percent'));
         if (abs($latestUSDExchange - $pcstoreAverageUSDExchange) / $latestUSDExchange > $maxAllowedDollarDifferenceParcent / 100) {
             $this->addCustomerMessage($custEmail, '483', 'Cba rate for USD Dollar ($) is: ' . $latestUSDExchange, 1, 'warning');
         }
     }
     //new added bonuses to user (users only)
     if ($userLevel === UserGroups::$USER) {
         $bonusHistoryManager = BonusHistoryManager::getInstance($this->config, $this->args);
         $userBonusesAfterGivenDatetime = $bonusHistoryManager->getUserBonusesAfterGivenDatetime($custDto->getId(), $previousPing);
         if (!empty($userBonusesAfterGivenDatetime)) {
             $pointSum = 0;
             foreach ($userBonusesAfterGivenDatetime as $bDto) {
                 $pointSum += intval($bDto->getPoints());
             }
             $pointSum = intval($pointSum);
             if ($pointSum > 0) {
                 $phraseId = '544';
             } else {
                 $phraseId = '548';
             }
             $this->addCustomerMessage($custEmail, '545', '`' . $phraseId . '` ' . strval(intval(abs($pointSum))) . 'դր.`542`', 1, 'attention');
         }
     }
     //new added sub users (users only)
     if ($userLevel === UserGroups::$USER) {
         $userSubUsersManager = UserSubUsersManager::getInstance($this->config, $this->args);
         $rowsAddedAfterGivenDatetime = $userSubUsersManager->getRowsAddedAfterGivenDatetime($custDto->getId(), $previousPing);
         if (!empty($rowsAddedAfterGivenDatetime)) {
             $this->addCustomerMessage($custEmail, '546', strval(count($rowsAddedAfterGivenDatetime)) . ' `547`', 1, 'attention');
         }
     }
     $customerLocalEmailsManager = CustomerLocalEmailsManager::getInstance($this->config, $this->args);
     $unreadEmailsCount = $customerLocalEmailsManager->getCustomerInboxUnreadEmailsCountCustomerEmail($custEmail);
     if ($unreadEmailsCount > 0) {
         $customerAlertsManager = CustomerAlertsManager::getInstance($this->config, $this->args);
         $customerAlertsManager->addUnreadEmailsCustomerAlert($custEmail, $unreadEmailsCount);
     }
 }
 public function sendNewPriceUploadedEmailToCompanyDealers($company)
 {
     $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
     $compayDealers = $companyDealersManager->getCompanyDealersUsersFullInfoHiddenIncluded($company->getId());
     $allUsersEmails = $this->getUsersEmailByUsersDtos($compayDealers);
     $emailSenderManager = new EmailSenderManager('gmail');
     $companyName = $company->getName();
     $subject = 'New Price form ' . $companyName . '!!!';
     $template = "new_price_uploaded";
     $params = array("company_name" => $companyName);
     $emailSenderManager->sendEmail('info', $allUsersEmails, $subject, $template, $params, '', '', true, true);
 }