Exemplo n.º 1
0
 /**
  * Initializes DB mappers
  *
  * @param object $config
  * @param object $args
  * @return
  */
 function __construct($config, $args)
 {
     $this->mapper = UserMapper::getInstance();
     $this->companyMapper = CompanyMapper::getInstance();
     $this->serviceCompanyMapper = ServiceCompanyMapper::getInstance();
     $this->serviceCompanyManager = ServiceCompanyManager::getInstance($config, $args);
     $this->adminMapper = AdminMapper::getInstance();
     $this->config = $config;
     $this->args = $args;
 }
 public function load()
 {
     $userLevel = $this->sessionManager->getUser()->getLevel();
     $serviceCompaniesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
     $serviceCompanyManager = ServiceCompanyManager::getInstance($this->config, $this->args);
     if ($userLevel === UserGroups::$SERVICE_COMPANY) {
         $serviceCompanyId = $this->getUserId();
         $selectedCompanyId = $serviceCompanyId;
         $serviceCompanyExtendedProfileManager = ServiceCompanyExtendedProfileManager::getInstance($this->config, $this->args);
         $dto = $serviceCompanyExtendedProfileManager->getByCompanyId($serviceCompanyId);
         if (!isset($dto)) {
             $serviceCompanyExtendedProfileManager->createDefaultExCompanyProfile($serviceCompanyId);
         }
         $dto = $serviceCompanyExtendedProfileManager->getByCompanyId($serviceCompanyId);
         list($companyEmailServerLogins, $companyEmailServersEmailsCount) = $this->getCompanyEmailServerLogins($dto);
         $this->addParam("companyEmailServerLogins", $companyEmailServerLogins);
         $this->addParam("companyEmailServersEmailsCount", $companyEmailServersEmailsCount);
         $this->addParam("companyExProfileDto", $dto);
         $dealerEmails = trim($dto->getDealerEmails());
         $this->addParam("total_price_email_recipients_count", empty($dealerEmails) ? 0 : count(explode(';', $dealerEmails)));
         array_map('unlink', glob(HTDOCS_TMP_DIR_ATTACHMENTS . "/service_companies/" . $serviceCompanyId . "/*"));
     } else {
         if ($userLevel === UserGroups::$ADMIN) {
             $allCompanies = $serviceCompanyManager->selectAll();
             $companiesIds = $serviceCompanyManager->getCompaniesIdsArray($allCompanies);
             $companiesNames = $serviceCompanyManager->getCompaniesNamesArray($allCompanies);
             if (isset($_REQUEST['selected_company'])) {
                 $selectedCompanyId = $this->secure($_REQUEST['selected_company']);
             } else {
                 $selectedCompanyId = $allCompanies[0]->getId();
             }
             $this->addParam("companiesIds", $companiesIds);
             $this->addParam("companiesNames", $companiesNames);
         }
     }
     $companyPrices = $serviceCompaniesPriceListManager->getCompanyHistoryPricesOrderByDate($selectedCompanyId, 0, 50);
     $this->addParam("company_prices", $companyPrices);
     $this->addParam("selectedCompanyId", $selectedCompanyId);
     if (isset($_REQUEST['show_send_email_to_dealers']) && $_REQUEST['show_send_email_to_dealers'] == 1) {
         $this->addParam("show_send_email_to_dealers", 1);
     }
     $emailServersManager = EmailServersManager::getInstance($this->config, $this->args);
     $allEmailServers = $emailServersManager->selectAll();
     $this->addParam("allEmailServers", $allEmailServers);
 }
 public function load()
 {
     $serviceCompanyManager = ServiceCompanyManager::getInstance($this->config, $this->args);
     if (!isset($_REQUEST['refresh']) && $_REQUEST['refresh'] != 1) {
         $companyLogin = $this->getCustomerLogin();
         if (isset($_REQUEST['password'])) {
             $password = $_REQUEST['password'];
             $dto = $serviceCompanyManager->getServiceCompanyByEmailAndPassword($companyLogin, $password);
             if (!isset($dto)) {
                 $this->addParam("message", $this->getPhraseSpan(581));
                 $this->addParam("checkPassword", 1);
                 return;
             }
         } else {
             $this->addParam("checkPassword", 1);
             return;
         }
     }
     $companyId = $this->getUserId();
     $companyAndBranchesDtos = $serviceCompanyManager->getCompanyAndBranches($companyId);
     $companyBranchesNamesIdsMap = $this->getCompanyBranchesNamesArrayByCompanyAndBranchesDtos($companyAndBranchesDtos);
     $selectedBranchNames = array_values($companyBranchesNamesIdsMap);
     $this->addParam("company_branches_names", $selectedBranchNames);
     $selectedBranchIds = array_keys($companyBranchesNamesIdsMap);
     $this->addParam("company_branches_ids", $selectedBranchIds);
     $selectedServiceCompanyBranchDto = null;
     if (isset($_REQUEST['selected_branch_id'])) {
         $selectedBranchId = intval($this->secure($_REQUEST['selected_branch_id']));
         if (array_key_exists($selectedBranchId, $companyBranchesNamesIdsMap)) {
             $selectedServiceCompanyBranchDto = $this->getCompanyBrancheByBranchId($companyAndBranchesDtos, $selectedBranchId);
         }
     }
     if (!isset($selectedServiceCompanyBranchDto)) {
         $selectedServiceCompanyBranchDto = $companyAndBranchesDtos[0];
     }
     if (!isset($selectedServiceCompanyBranchDto)) {
         echo 'Error: no company branch data!';
         exit;
     }
     $this->addParam("selected_company_branch_id", $selectedServiceCompanyBranchDto->getBranchId());
     $companyPhones = trim($selectedServiceCompanyBranchDto->getPhones());
     $companyPhonesArray = array();
     if (!empty($companyPhones)) {
         $companyPhonesArray = explode(',', $companyPhones);
     }
     $this->addParam("phones", $companyPhonesArray);
     $this->addParam("working_days", $selectedServiceCompanyBranchDto->getWorkingDays());
     $this->addParam("branch_address", $selectedServiceCompanyBranchDto->getStreet());
     $this->addParam("lat", $selectedServiceCompanyBranchDto->getLat());
     $this->addParam("lng", $selectedServiceCompanyBranchDto->getLng());
     $regions_phrase_ids_array = explode(',', $this->getCmsVar('armenia_regions_phrase_ids'));
     $this->addParam('regions_phrase_ids_array', $regions_phrase_ids_array);
     $region = trim($selectedServiceCompanyBranchDto->getRegion());
     $this->addParam('region_selected', $region);
     $minutes_block = 30;
     $start_time = '00:00:00';
     $total_day_minutes = 24 * 60;
     $cycleIndex = -1;
     $times = array();
     while (++$cycleIndex * $minutes_block < $total_day_minutes) {
         $timestamp = strtotime($start_time);
         $mins = $cycleIndex * $minutes_block;
         $time = strtotime("+{$mins} minutes", $timestamp);
         $times[] = date('H:i', $time);
     }
     $this->addParam('times', $times);
 }
Exemplo n.º 4
0
 public function service()
 {
     $userManager = new UserManager($this->config, $this->args);
     if (isset($_REQUEST['login_type'])) {
         $json_profile = $_REQUEST['json_profile'];
         $social_user_id = $this->secure($_REQUEST['social_user_id']);
         $first_name = $this->secure($_REQUEST['first_name']);
         $last_name = $this->secure($_REQUEST['last_name']);
         $custDto = $userManager->getUserByEmail($social_user_id);
         if (!isset($custDto)) {
             $userId = $userManager->createUser($social_user_id, uniqid(), $first_name, '', $last_name, $_REQUEST['login_type']);
             $userManager->setActive($userId);
             $userManager->setUserSocialProfile($userId, $json_profile);
             $custDto = $userManager->getUserByEmail($social_user_id);
             //bonus to inviter
             $invitation_code = $this->secure($_COOKIE["invc"]);
             $inviterId = $userManager->setSubUser($invitation_code, $userId);
             if ($inviterId > 0) {
                 $invbonus = intval($this->getCmsVar("bonus_points_for_every_accepted_invitation"));
                 $userManager->addUserPoints($inviterId, $invbonus, "{$invbonus} bonus for invitation accept from user number: {$userId}");
             }
         }
         $userType = UserGroups::$USER;
     } else {
         $email = strtolower($userManager->secure($_REQUEST["user_email"]));
         $pass = $userManager->secure($_REQUEST["user_pass"]);
         $custDto = $userManager->getCustomerByEmailAndPassword($email, $pass);
         $userType = $userManager->getCustomerType($email, $pass);
         if ($userType == UserGroups::$USER && $custDto->getActive() == 0) {
             $jsonArr = array('status' => "err", "errText" => sprintf($this->getPhrase(380), $custDto->getEmail()));
             echo json_encode($jsonArr);
             return false;
         }
     }
     if ($custDto) {
         if ($userType !== UserGroups::$ADMIN && $custDto->getBlocked() == 1) {
             $jsonArr = array('status' => "err", "errText" => $this->getPhraseSpan(411) . ' ' . $this->getCmsVar("pcstore_support_phone_number"));
             echo json_encode($jsonArr);
             return false;
         }
         $user = null;
         if ($userType === UserGroups::$ADMIN) {
             $user = new AdminUser($custDto->getId());
         } else {
             if ($userType === UserGroups::$USER) {
                 $user = new CustomerUser($custDto->getId());
                 $this->setcookie('ul', $custDto->getLanguageCode());
             } else {
                 if ($userType === UserGroups::$COMPANY) {
                     $user = new CompanyUser($custDto->getId());
                     $companyManager = CompanyManager::getInstance($this->config, $this->args);
                     $companyManager->updateCompanyRating($custDto);
                     $this->setcookie('ul', $custDto->getLanguageCode());
                 } else {
                     if ($userType === UserGroups::$SERVICE_COMPANY) {
                         $user = new ServiceCompanyUser($custDto->getId());
                         $companyManager = ServiceCompanyManager::getInstance($this->config, $this->args);
                         $this->setcookie('ul', $custDto->getLanguageCode());
                     }
                 }
             }
         }
         $user->setUniqueId($custDto->getHash());
         $this->sessionManager->setUser($user, true, true);
         $jsonArr = array('status' => "ok");
         echo json_encode($jsonArr);
         return true;
     } else {
         $jsonArr = array('status' => "err", "errText" => $this->getPhrase(412));
         echo json_encode($jsonArr);
         return false;
     }
 }
 private function determineCompanyIdFromPriceEmail($fromEmails)
 {
     if (is_array($fromEmails)) {
         $fromEmails = implode(',', $fromEmails);
     }
     $companyManager = CompanyManager::getInstance(null, null);
     $allCompaniesDtos = $companyManager->selectAll();
     $selectedCompaniesIds = array();
     foreach ($allCompaniesDtos as $companyDto) {
         $companyEmail = $companyDto->getEmail();
         $priceEmailsKeywords = trim($companyDto->getPriceEmailsKeywords());
         $priceEmailsKeywordsArray = array();
         if (!empty($priceEmailsKeywords)) {
             $priceEmailsKeywordsArray = explode(',', $priceEmailsKeywords);
         }
         if (strpos($fromEmails, $companyEmail) !== false) {
             return array($companyDto->getId(), $companyDto->getName(), 'company');
         }
         foreach ($priceEmailsKeywordsArray as $priceEmailsKeyword) {
             if (strpos($fromEmails, $priceEmailsKeyword) !== false) {
                 $selectedCompaniesIds[$companyDto->getId()] = $companyDto->getName();
             }
         }
     }
     $serviceCompanyManager = ServiceCompanyManager::getInstance(null, null);
     $allServiceCompaniesDtos = $serviceCompanyManager->selectAll();
     $selectedServiceCompaniesIds = array();
     foreach ($allServiceCompaniesDtos as $serviceCompanyDto) {
         $serviceCompanyEmail = $serviceCompanyDto->getEmail();
         $priceEmailsKeywords = $serviceCompanyDto->getPriceEmailsKeywords();
         if (!empty($priceEmailsKeywords)) {
             $priceEmailsKeywordsArray = explode(',', $priceEmailsKeywords);
         }
         if (strpos($fromEmails, $serviceCompanyEmail) !== false) {
             return array($serviceCompanyDto->getId(), $serviceCompanyDto->getName(), 'service_company');
         }
         foreach ($priceEmailsKeywordsArray as $priceEmailsKeyword) {
             if (strpos($fromEmails, $priceEmailsKeyword) !== false) {
                 $selectedServiceCompaniesIds[$serviceCompanyDto->getId()] = $serviceCompanyDto->getName();
             }
         }
     }
     if (count($selectedCompaniesIds) === 1) {
         $keys = array_keys($selectedCompaniesIds);
         return array($keys[0], $selectedCompaniesIds[$keys[0]], 'company');
     }
     if (count($selectedServiceCompaniesIds) === 1) {
         $keys = array_keys($selectedServiceCompaniesIds);
         return array($keys[0], $selectedServiceCompaniesIds[$keys[0]], 'service_company');
     }
     //@TODO retrun the correct company id and type
     return array(false, false, false);
 }
Exemplo n.º 6
0
 public function load()
 {
     $this->setDescriptionTagValue('Companies that are registered in pcstore.am and their products are listed.');
     $this->setTitleTagValue('Pcstore Company List');
     $this->setKeywordsTagValue('Companies that are registered in pcstore.am and their products are listed.');
     $companyManager = CompanyManager::getInstance($this->config, $this->args);
     $serviceCompanyManager = ServiceCompanyManager::getInstance($this->config, $this->args);
     $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
     $serviceCompaniesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
     $show_only_last_hours_values = array(0, 10, 24, 72, 168);
     $ph_all = $this->getPhrase(461);
     $ph_last = $this->getPhrase(456);
     $ph_hours = $this->getPhrase(455);
     $ph_days = $this->getPhrase(459);
     $ph_week = $this->getPhrase(460);
     $ph_updated = $this->getPhrase(457);
     $show_only_last_hours_names_phrase_ids_array = array(461, "`456` 10 `455` `457`", "`456` 24 `455` `457`", "`456` 3 `459` `457`", "`456` `460` `457`");
     $show_only_last_hours_names = array($ph_all, $ph_last . ' 10 ' . $ph_hours . ' ' . $ph_updated, $ph_last . ' 24 ' . $ph_hours . ' ' . $ph_updated, $ph_last . ' 3 ' . $ph_days . ' ' . $ph_updated, $ph_last . ' ' . $ph_week . ' ' . $ph_updated);
     $show_only_last_hours_selected = 0;
     if (isset($_REQUEST['show_only_last_hours_selected'])) {
         $show_only_last_hours_selected = intval($_REQUEST['show_only_last_hours_selected']);
     }
     $this->addParam("show_only_last_hours_values", $show_only_last_hours_values);
     $this->addParam("show_only_last_hours_names", $show_only_last_hours_names);
     $this->addParam("show_only_last_hours_names_phrase_ids_array", $show_only_last_hours_names_phrase_ids_array);
     $this->addParam("show_only_last_hours_selected", $show_only_last_hours_selected);
     $searchText = "";
     if (isset($_REQUEST['search_text'])) {
         $searchText = $this->secure($_REQUEST['search_text']);
     }
     $this->addParam("search_text", $searchText);
     $userLevel = $this->getUserLevel();
     $userId = $this->getUserId();
     $companiesList = array();
     $allServiceCompaniesWithBranches = $serviceCompanyManager->getAllServiceCompaniesWithBranches();
     foreach ($allServiceCompaniesWithBranches as $serviceCompanyDto) {
         $serviceCompanyDto->setShowPrice(1);
     }
     if ($userLevel == UserGroups::$USER) {
         $serviceCompanyDealersManager = ServiceCompanyDealersManager::getInstance($this->config, $this->args);
         $userserviceCompaniesIdsArray = $serviceCompanyDealersManager->getUserCompaniesIdsArray($userId);
         foreach ($allServiceCompaniesWithBranches as $serviceCompanyDto) {
             if (in_array($serviceCompanyDto->getId(), $userserviceCompaniesIdsArray)) {
                 $serviceCompanyDto->setShowPrice(1);
             } else {
                 $serviceCompanyDto->setShowPrice(0);
             }
         }
     }
     if ($userLevel == UserGroups::$COMPANY || $userLevel == UserGroups::$SERVICE_COMPANY) {
         $companiesList = $companyManager->getAllCompaniesByPriceHours($show_only_last_hours_selected, $searchText);
     }
     if ($userLevel == UserGroups::$USER) {
         $companiesList = $companyManager->getUserCompaniesJoindWithFullInfo($userId, $show_only_last_hours_selected, $searchText);
     }
     if ($userLevel == UserGroups::$ADMIN) {
         $companiesList = $companyManager->getAllCompaniesByPriceHours($show_only_last_hours_selected, $searchText, true, true);
     }
     $this->addParam('allCompanies', $companiesList);
     $this->addParam('allServiceCompanies', $allServiceCompaniesWithBranches);
     $allNonHiddenCompanies = $companyManager->getAllCompanies();
     $this->addParam('allNonHiddenCompanies', $allNonHiddenCompanies);
     $this->addParam('allCompaniesDtosToArray', json_encode(AbstractDto::dtosToArray($companiesList, array("id" => "id", "name" => "name", "rating" => "rating"))));
     $this->addParam('allServiceCompaniesDtosToArray', json_encode(AbstractDto::dtosToArray($allServiceCompaniesWithBranches, array("id" => "id", "name" => "name"))));
     // $this->addParam('userLevel', $userLevel);
     // $this->addParam('userGroupsUser', UserGroups::$USER);
     $companyBranchesManager = CompanyBranchesManager::getInstance($this->config, $this->args);
     $serviceCompanyBranchesManager = ServiceCompanyBranchesManager::getInstance($this->config, $this->args);
     $cids = $this->getCompanyIdsArray($companiesList);
     $scids = $this->getCompanyIdsArray($allServiceCompaniesWithBranches);
     $companiesBranchesDtos = $companyBranchesManager->getCompaniesBranches($cids);
     $serviceCompaniesBranchesDtos = $serviceCompanyBranchesManager->getServiceCompaniesBranches($scids);
     $this->addParam('allCompaniesBranchesDtosToArray', json_encode(AbstractDto::dtosToArray($companiesBranchesDtos)));
     $this->addParam('allServiceCompaniesBranchesDtosToArray', json_encode(AbstractDto::dtosToArray($serviceCompaniesBranchesDtos)));
     $this->addParam("companiesPriceListManager", $companiesPriceListManager);
     $this->addParam("serviceCompaniesPriceListManager", $serviceCompaniesPriceListManager);
     $companiesZippedPricesByDaysNumber = $companiesPriceListManager->getCompaniesZippedPricesByDaysNumber($cids, 360);
     $serviceCompaniesZippedPricesByDaysNumber = $serviceCompaniesPriceListManager->getCompaniesZippedPricesByDaysNumber($cids, 360);
     $groupCompaniesZippedPricesByCompanyId = $this->groupCompaniesZippedPricesByCompanyId($companiesZippedPricesByDaysNumber);
     $groupServiceCompaniesZippedPricesByCompanyId = $this->groupServiceCompaniesZippedPricesByCompanyId($serviceCompaniesZippedPricesByDaysNumber);
     $this->addParam("groupCompaniesZippedPricesByCompanyId", $groupCompaniesZippedPricesByCompanyId);
     $this->addParam("groupServiceCompaniesZippedPricesByCompanyId", $groupServiceCompaniesZippedPricesByCompanyId);
 }
Exemplo n.º 7
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 createDefaultExCompanyProfile($companyId)
 {
     $dto = $this->mapper->createDto();
     $dto->setServiceCompanyId($companyId);
     $serviceCompanyManager = ServiceCompanyManager::getInstance($this->config, $this->args);
     $serviceCompanyBranchesManager = ServiceCompanyBranchesManager::getInstance($this->config, $this->args);
     $companyDto = $serviceCompanyManager->selectByPK($companyId);
     $companyBranches = $serviceCompanyBranchesManager->getServiceCompaniesBranches($companyId);
     list($phones, $addresses) = $this->getCompanyPhonesAndAddressesFromBranches($companyBranches);
     $emailBodyTemplate = $this->getPhrase(587);
     $emailBody = str_replace(array('{company_access_code}', '{service_company_id}', '{company_addresses}', '{company_phones}'), array($companyDto->getAccessKey(), $companyId, implode('<br>', $addresses), implode('<br>', $phones)), $emailBodyTemplate);
     $dto->setPriceEmailBody($emailBody);
     $dto->setPriceEmailSubject($companyDto->getName() . ' Price');
     $this->mapper->insertDto($dto);
 }
Exemplo n.º 9
0
 /**
  * Creates en instance of admin user class and
  * initializes class members necessary for validation. 
  * 
  * @param object $adminId
  * @return 
  */
 public function __construct($id)
 {
     parent::__construct($id);
     $this->setCookieParam("ut", UserGroups::$SERVICE_COMPANY);
     $this->serviceCompanyManager = ServiceCompanyManager::getInstance(null, null);
 }