/**
  * 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 ServiceCompanyManager($config, $args);
     }
     return self::$instance;
 }
Exemplo n.º 2
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 service()
 {
     $serviceCompanyManager = new ServiceCompanyManager($this->config, $this->args);
     $serviceCompanyDealersManager = new ServiceCompanyDealersManager($this->config, $this->args);
     $access_key = $this->secure($_REQUEST["access_key"]);
     $service_company_id = $this->secure($_REQUEST["service_company_id"]);
     $serviceCompany = $serviceCompanyManager->selectByPK($service_company_id);
     if (!isset($serviceCompany)) {
         $this->error(array("errText" => "System error! Company doesn't exists."));
     }
     if (strcasecmp($access_key, $serviceCompany->getAccessKey()) != 0) {
         $this->error(array("errText" => "Wrong access key!"));
     }
     $userId = $this->getUserId();
     $companyDealerDto = $serviceCompanyDealersManager->getByCompanyIdAndUserId($userId, $service_company_id);
     if (!isset($companyDealerDto)) {
         $serviceCompanyDealersManager->addUserToCompany($userId, $service_company_id);
         $message = $this->getPhrase(437) . ' ' . $serviceCompany->getName() . "'! \n";
         $this->ok(array("message" => $message));
     } else {
         $this->error(array("errText" => "You already have '" . $serviceCompany->getName() . "' company in your list!"));
     }
 }
 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.º 6
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;
     }
 }
Exemplo n.º 7
0
 public function getCustomer()
 {
     if (!$this->customer) {
         if ($this->getUserLevel() != UserGroups::$GUEST) {
             $userId = $this->getUserId();
             if ($this->getUserLevel() == UserGroups::$USER) {
                 $userManager = new UserManager($this->config, $this->args);
                 $this->customer = $userManager->selectByPK($userId);
             } else {
                 if ($this->getUserLevel() == UserGroups::$COMPANY) {
                     $customerManager = new CompanyManager($this->config, $this->args);
                     $this->customer = $customerManager->selectByPK($userId);
                 } else {
                     if ($this->getUserLevel() == UserGroups::$SERVICE_COMPANY) {
                         $customerManager = new ServiceCompanyManager($this->config, $this->args);
                         $this->customer = $customerManager->selectByPK($userId);
                     } else {
                         if ($this->getUserLevel() == UserGroups::$ADMIN) {
                             $adminManager = new AdminManager($this->config, $this->args);
                             $this->customer = $adminManager->selectByPK($userId);
                         }
                     }
                 }
             }
         }
     }
     return $this->customer;
 }
 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.º 9
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);
 }
 public function service()
 {
     //getting parameters
     ini_set('upload_max_filesize', '7M');
     $name = $_FILES['company_price']['name'];
     $type = $_FILES['company_price']['type'];
     $tmp_name = $_FILES['company_price']['tmp_name'];
     $size = $_FILES['company_price']['size'];
     $response = $this->checkInputFile('company_price');
     if ($response !== 'ok') {
         $jsonArr = array('status' => "err", "errText" => $response);
         echo "<script>var l= new parent.ngs.UploadServiceCompanyPriceAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
         return false;
     }
     if (!$size || $size > 7 * 1024 * 1024) {
         $jsonArr = array('status' => "err", "errText" => "Maximum file size can be 7MB");
         echo "<script>var l= new parent.ngs.UploadServiceCompanyPriceAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
         return false;
     }
     //start to save new price file
     $fname = explode('.', $name);
     end($fname);
     $newFileExt = current($fname);
     if (!in_array($newFileExt, $this->supported_file_formats)) {
         $jsonArr = array('status' => "err", "errText" => "Not supported file format!");
         echo "<script>var l= new parent.ngs.UploadServiceCompanyPriceAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
         return false;
     }
     $userLevel = $this->getUserLevel();
     if ($userLevel === UserGroups::$ADMIN) {
         $serviceCompanyId = $this->secure($_REQUEST["up_selected_service_company"]);
     } else {
         if ($userLevel === UserGroups::$SERVICE_COMPANY) {
             $serviceCompanyId = $this->getUserId();
             assert($serviceCompanyId == $this->secure($_REQUEST["up_selected_service_company"]));
         } else {
             $jsonArr = array('status' => "err", "errText" => "Not Access!");
             echo "<script>var l= new parent.ngs.UploadServiceCompanyPriceAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
             return false;
         }
     }
     $dir = DATA_DIR . "/service_companies_prices/";
     if (!is_dir($dir)) {
         mkdir($dir, 0777);
     }
     $dir = DATA_DIR . "/service_companies_prices/" . $serviceCompanyId . '/';
     if (!is_dir($dir)) {
         mkdir($dir, 0777);
     }
     $company_duplicated_price_upload_hours = $this->getCmsVar('company_duplicated_price_upload_hours');
     $serviceCompaniesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
     $company_price_upload_a_day_max_count = $this->getCmsVar('company_price_upload_a_day_max_count');
     if (isset($_REQUEST['merge_into_last_price']) && $_REQUEST['merge_into_last_price'] == 1) {
         $duplicatedUpload = $this->checkIfSamePriceAlreadyExists($serviceCompanyId, $tmp_name);
         $companyLastPriceMinutes = $serviceCompaniesPriceListManager->getCompanyLastPriceMinutes($serviceCompanyId);
         if ($companyLastPriceMinutes / 60 < $company_duplicated_price_upload_hours && $duplicatedUpload) {
             $jsonArr = array('status' => "err", "errText" => "Same Price already exists! please try in " . $company_duplicated_price_upload_hours . " hours.");
             echo "<script>var l= new parent.ngs.UploadServiceCompanyPriceAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
             return false;
         }
         $companyLastPriceDtos = $serviceCompaniesPriceListManager->getCompanyLastPrices($serviceCompanyId);
         $companyLastPriceInfoDto = end($companyLastPriceDtos);
         $lastPriceName = $companyLastPriceInfoDto->getFileName();
         $newFileName = $lastPriceName . '_' . (count($companyLastPriceDtos) + 1);
         $newFileFullName = $dir . $newFileName . '.' . $newFileExt;
         move_uploaded_file($tmp_name, $newFileFullName);
         $serviceCompaniesPriceListManager->addCompanyPrice($serviceCompanyId, $newFileName, $newFileExt, $userLevel == UserGroups::$ADMIN ? "admin" : "servicecompany", $this->getUserId());
         $jsonArr = array('status' => "ok");
         echo "<script>var l= new parent.ngs.UploadCompanyPriceAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
         return true;
     }
     $companyTodayPriceUploadedTimes = $serviceCompaniesPriceListManager->getCompanyTodayPriceUploadedTimes($serviceCompanyId);
     if ($companyTodayPriceUploadedTimes >= $company_price_upload_a_day_max_count) {
         $jsonArr = array('status' => "err", "errText" => "You exeeded your daily maximum upload count! (max:" . $company_price_upload_a_day_max_count . " times a day)");
         echo "<script>var l= new parent.ngs.UploadServiceCompanyPriceAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
         return false;
     }
     $serviceCompanyLastPriceMinutes = $serviceCompaniesPriceListManager->getCompanyLastPriceMinutes($serviceCompanyId);
     $duplicatedUpload = $this->checkIfSamePriceAlreadyExists($serviceCompanyId, $tmp_name);
     if ($serviceCompanyLastPriceMinutes / 60 < $company_duplicated_price_upload_hours && $duplicatedUpload) {
         $jsonArr = array('status' => "err", "errText" => "Sorry You can not upload same price in " . $company_duplicated_price_upload_hours . " hours. Your company last uploaded price seams to be same as this one!");
         echo "<script>var l= new parent.ngs.UploadServiceCompanyPriceAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
         return false;
     }
     $companyLastPriceDtos = $serviceCompaniesPriceListManager->getCompanyLastPrices($serviceCompanyId);
     if (!empty($companyLastPriceDtos)) {
         $companyLastPriceFirstUploadedDto = end($companyLastPriceDtos);
         $lastPriceFiles = array();
         $lastPriceFileName = $companyLastPriceFirstUploadedDto->getFileName();
         foreach ($companyLastPriceDtos as $key => $companyLastPriceDto) {
             $lastPriceName = $companyLastPriceDto->getFileName();
             $lastPriceExt = $companyLastPriceDto->getFileExt();
             $lastPriceFiles[] = array($dir . $lastPriceName . '.' . $lastPriceExt, $lastPriceName . '.' . $lastPriceExt);
         }
         $this->createZip($lastPriceFiles, $dir . $lastPriceFileName . '.zip');
         $lastPriceUploadedDateTime = $companyLastPriceFirstUploadedDto->getUploadDateTime();
         $lastPriceUploaderType = $companyLastPriceFirstUploadedDto->getUploaderType();
         $lastPriceUploaderId = $companyLastPriceFirstUploadedDto->getUploaderId();
         foreach ($companyLastPriceDtos as $key => $companyLastPriceDto) {
             $lastPriceName = $companyLastPriceDto->getFileName();
             $lastPriceExt = $companyLastPriceDto->getFileExt();
             if (is_file($dir . $lastPriceName . '.' . $lastPriceExt)) {
                 unlink($dir . $lastPriceName . '.' . $lastPriceExt);
             }
             $serviceCompaniesPriceListManager->deleteByPK($companyLastPriceDto->getId());
         }
         $serviceCompaniesPriceListManager->addCompanyPrice($serviceCompanyId, $lastPriceFileName, 'zip', $lastPriceUploaderType, $lastPriceUploaderId, $lastPriceUploadedDateTime);
     }
     $now = date("Y-m-d-H-i-s");
     $newFileName = 'price_' . $now;
     $newFileFullName = $dir . $newFileName . '.' . $newFileExt;
     move_uploaded_file($tmp_name, $newFileFullName);
     $serviceCompaniesPriceListManager->addCompanyPrice($serviceCompanyId, $newFileName, $newFileExt, $userLevel == UserGroups::$ADMIN ? "admin" : "servicecompany", $this->getUserId());
     $jsonArr = array('status' => "ok");
     echo "<script>var l= new parent.ngs.UploadServiceCompanyPriceAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
     $serviceCompanyManager = new ServiceCompanyManager($this->config, $this->args);
     $serviceCompany = $serviceCompanyManager->selectByPK($serviceCompanyId);
     //$this->sendNewEmailUploadedToAllCompanyAccessedCustomers($company);
     if ($this->getCmsVar('enable_upload_price_alert') == 1) {
         $this->addEventIntoEventsTableForOnlineCustomers($serviceCompany);
     }
     $this->sendSmsToAdminIfUploaderIsNotItself($serviceCompany->getName());
     return true;
 }
Exemplo n.º 11
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);
 }
 public function service()
 {
     $serviceCompanyManager = new ServiceCompanyManager($this->config, $this->args);
     $this->userManager = new UserManager($this->config, $this->args);
     $company_branch_id = $this->secure($_REQUEST["cp_branch_select"]);
     $company_name = $this->secure($_REQUEST["company_name"]);
     $accessKey = $this->secure($_REQUEST["dealers_access_key"]);
     $change_pass = $this->secure($_REQUEST["change_pass"]);
     $new_pass = $this->secure($_REQUEST["new_pass"]);
     $repeat_new_pass = $this->secure($_REQUEST["repeat_new_pass"]);
     $phone1 = $this->secure($_REQUEST["phone1"]);
     $phone2 = $this->secure($_REQUEST["phone2"]);
     $phone3 = $this->secure($_REQUEST["phone3"]);
     $address = $this->secure($_REQUEST["address"]);
     $region = $this->secure($_REQUEST["region"]);
     $lng = $this->secure($_REQUEST["longitute"]);
     $lat = $this->secure($_REQUEST["latitude"]);
     $working_days = $this->secure($_REQUEST["working_days"]);
     $working_hours = $this->secure($_REQUEST["working_hours"]);
     $zip = $this->secure($_REQUEST["zip"]);
     $url = $this->secure($_REQUEST["url"]);
     $validFields = $this->validateCompanyProfileFields($company_name, $change_pass, $new_pass, $repeat_new_pass, $phone1, $phone2, $phone3, $address, $zip, $region, $working_days, $working_hours, $url);
     $companyId = $this->getUserId();
     if ($validFields === 'ok') {
         if (isset($_FILES['service_company_logo'])) {
             ////////////////////////////
             $originalLogoFullName = null;
             $file_name = $_FILES['service_company_logo']['name'];
             $file_type = $_FILES['service_company_logo']['type'];
             $tmp_name = $_FILES['service_company_logo']['tmp_name'];
             $file_size = $_FILES['service_company_logo']['size'];
             $logoCheck = $this->checkInputFile('service_company_logo');
             //start to save new price file
             $logoExt = end(explode('.', $file_name));
             if ($logoCheck === 'ok' && !in_array($logoExt, $this->supported_file_formats)) {
                 $logoCheck = "Not supported file format! ()";
             }
             if ($logoCheck === 'ok') {
                 $dir = DATA_DIR . "/images/";
                 if (!is_dir($dir)) {
                     mkdir($dir, 0777);
                 }
                 $dir = DATA_DIR . "/images/service_company_logo/";
                 if (!is_dir($dir)) {
                     mkdir($dir, 0777);
                 }
                 $logoName = 'service_company_' . $companyId . '_logo';
                 $originalLogoFullName = $dir . $logoName . '_original' . '.' . 'png';
                 $resizedLogoFullName_55_30 = $dir . $logoName . '_55_30' . '.' . 'png';
                 $resizedLogoFullName_120_75 = $dir . $logoName . '_120_75' . '.' . 'png';
                 move_uploaded_file($tmp_name, $originalLogoFullName);
                 $resret1 = resizeImageToGivenType($originalLogoFullName, $resizedLogoFullName_55_30, 55, 30, 'png');
                 $resret2 = resizeImageToGivenType($originalLogoFullName, $resizedLogoFullName_120_75, 120, 75, 'png');
                 //resize image
                 if ($logoCheck === 'ok' && $resret1 == false) {
                     $logoCheck = "Error resizing image!";
                 }
                 if (is_file($originalLogoFullName)) {
                     unlink($originalLogoFullName);
                 }
             }
         }
         $sms_phone_number = '';
         if (isset($_REQUEST['enable_sms_on_price_upload'])) {
             $sms_phone_number = $this->secure($_REQUEST['sms_phone_number']);
         }
         $sms_from_time = date('H:i:s', strtotime($this->secure($_REQUEST['sms_from_time'])));
         $sms_to_duration_minutes = 0;
         if (isset($_REQUEST['sms_time_control'])) {
             $sms_to_duration_minutes = $this->secure($_REQUEST['sms_to_duration_minutes']);
         }
         $sms_receiving_days = $this->secure($_REQUEST['sms_receiving_days']);
         $serviceCompanyManager->updateCompanyProfileFieldsById($companyId, $company_branch_id, $company_name, $change_pass, $new_pass, $accessKey, $phone1, $phone2, $phone3, $address, $zip, $region, $working_days, $working_hours, $url, $lng, $lat);
         $jsonArr = array('status' => "ok", "message" => $logoCheck);
         echo "<script>var l= new parent.ngs.ChangeServiceCompanyProfileAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
         return true;
         ////////////////////////////
     } else {
         $jsonArr = array('status' => "err", "errText" => $validFields);
         echo "<script>var l= new parent.ngs.ChangeServiceCompanyProfileAction(); l.afterAction('" . json_encode($jsonArr) . "'); </script>";
         return false;
     }
 }
Exemplo n.º 14
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);
 }