/**
  * 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 CustomerAlertsManager($config, $args);
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
 public function service()
 {
     $onlineUserManager = new OnlineUsersManager($this->config, $this->args);
     $customer = $this->getCustomer();
     if ($this->getUserLevel() !== UserGroups::$GUEST) {
         //add to online users table
         $customerEmail = $customer->getEmail();
         $newAdded = $onlineUserManager->addOnlineUser($this->getUserLevel(), $customer) > 0;
         if ($newAdded) {
             $customerMessagesAfterLoginManager = CustomerMessagesAfterLoginManager::getInstance($this->config, $this->args);
             $customerAfterLoginMessagesDtos = $customerMessagesAfterLoginManager->getCustomerMessages($customer->getEmail());
             $customerMessagesAfterLoginManager->incrementCustomerMessagesShowedCount($customerAfterLoginMessagesDtos);
             $customerAfterLoginMessagesDtosToArray = AbstractDto::dtosToArray($customerAfterLoginMessagesDtos);
         }
         //check user alerts
         $winUid = $_REQUEST['win_uid'];
         $customerAlertListManager = CustomerAlertListManager::getInstance($this->config, $this->args);
         $registeredCustomerAlertsDtosToArray = $customerAlertListManager->getRegisteredCustomerAlerts($customer, $winUid);
         $customerAlertsManager = CustomerAlertsManager::getInstance($this->config, $this->args);
         $customerMessagesDtos = $customerAlertsManager->getCustomerAlertsByCustomerLogin($customerEmail, $winUid);
         $customerMessagesToPhpArray = AbstractDto::dtosToArray($customerMessagesDtos);
     } else {
         //add guest in online users table
         $guest_online_table_id = $_COOKIE['guest_online_table_id'];
         if ($guest_online_table_id) {
             $onlineUser = $onlineUserManager->selectByPK($guest_online_table_id);
             if (isset($onlineUser)) {
                 $onlineUserManager->updateOnlineUserAttributes($onlineUser);
             } else {
                 $newId = $onlineUserManager->addOnlineUser($this->getUserLevel(), null);
                 if (isset($newId)) {
                     $this->setcookie('guest_online_table_id', $newId);
                 }
             }
         } else {
             $newId = $onlineUserManager->addOnlineUser($this->getUserLevel(), null);
             if (isset($newId)) {
                 $this->setcookie('guest_online_table_id', $newId);
             }
         }
     }
     $jsonArr = array('status' => "ok");
     if (!empty($registeredCustomerAlertsDtosToArray)) {
         $jsonArr['alerts'] = $registeredCustomerAlertsDtosToArray;
     }
     if (!empty($customerAfterLoginMessagesDtosToArray)) {
         $jsonArr['customer_after_login_messages'] = $customerAfterLoginMessagesDtos;
     }
     if (!empty($customerMessagesToPhpArray)) {
         $jsonArr['messages'] = $customerMessagesToPhpArray;
     }
     echo json_encode($jsonArr);
     return true;
 }
 public function addEventIntoEventsTableForOnlineCustomers($to_emails_array, $fromName, $subject)
 {
     $customerAlertsManager = CustomerAlertsManager::getInstance($this->config, $this->args);
     $onlineUsersManager = OnlineUsersManager::getInstance($this->config, $this->args);
     $customerLocalEmailsManager = CustomerLocalEmailsManager::getInstance($this->config, $this->args);
     $onlineRegisteredCustomers = $onlineUsersManager->getOnlineRegisteredCustomers();
     foreach ($onlineRegisteredCustomers as $onlineUsersDto) {
         $custEmail = $onlineUsersDto->getEmail();
         if (in_array($custEmail, $to_emails_array)) {
             $customerInboxUnreadEmailsCount = $customerLocalEmailsManager->getCustomerInboxUnreadEmailsCountCustomerEmail($custEmail);
             $customerAlertsManager->addNewEmailCustomerAlert($custEmail, $fromName, $subject, $customerInboxUnreadEmailsCount, $onlineUsersDto->getLanguageCode());
         }
     }
 }
 public function addEventIntoEventsTableForOnlineCustomers($company)
 {
     $customerAlertsManager = CustomerAlertsManager::getInstance($this->config, $this->args);
     $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
     $onlineUsersManager = OnlineUsersManager::getInstance($this->config, $this->args);
     $userManager = UserManager::getInstance($this->config, $this->args);
     $onlineRegisteredCustomers = $onlineUsersManager->getOnlineRegisteredCustomers();
     foreach ($onlineRegisteredCustomers as $onlineUsersDto) {
         $customerType = $userManager->getCustomerTypeByEmail($onlineUsersDto->getEmail());
         if ($customerType === UserGroups::$USER) {
             $userCustomer = $userManager->getUserByEmail($onlineUsersDto->getEmail());
             $dealerDto = $companyDealersManager->getByCompanyIdAndUserId($userCustomer->getId(), $company->getId());
             if (isset($dealerDto)) {
                 $customerAlertsManager->addPriceUploadCustomerAlert($onlineUsersDto->getEmail(), $company, $onlineUsersDto->getLanguageCode());
             }
         } elseif ($customerType === UserGroups::$COMPANY || $customerType === UserGroups::$ADMIN) {
             $customerAlertsManager->addPriceUploadCustomerAlert($onlineUsersDto->getEmail(), $company);
         }
     }
 }
Ejemplo n.º 5
0
 public function checkPriceEmailsAndAddAlertsToOnlineAdmins()
 {
     $emailServersManager = new EmailAccountsManager(null, null);
     $infoEmailDto = $emailServersManager->selectByPK('info');
     $login = $infoEmailDto->getLogin();
     $pass = $infoEmailDto->getPass();
     $imapInbox = $infoEmailDto->getImapInbox();
     $connection = @imap_open($imapInbox, $login, $pass);
     if (!$connection) {
         return imap_last_error();
     }
     $emailsIds = imap_search($connection, 'UNSEEN');
     if (empty($emailsIds) || !is_array($emailsIds)) {
         return "No unread emails";
     }
     rsort($emailsIds);
     $attachments = array();
     foreach ($emailsIds as $emailId) {
         //$overview = imap_fetch_overview($connection, $emailId, 0);
         $structure = imap_fetchstructure($connection, $emailId);
         $header = imap_headerinfo($connection, $emailId);
         $fromEmails = array();
         if (!empty($header->from)) {
             foreach ($header->from as $from) {
                 $fromEmails[] = $from->mailbox . '@' . $from->host;
             }
         }
         list($companyId, $companyName, $companyType) = $this->determineCompanyIdFromPriceEmail($fromEmails);
         if ($companyId == false) {
             continue;
         }
         if (isset($structure->parts) && count($structure->parts)) {
             for ($i = 0; $i < count($structure->parts); $i++) {
                 $attachments[$emailId][$i] = array('is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '');
                 if ($structure->parts[$i]->ifdparameters) {
                     foreach ($structure->parts[$i]->dparameters as $object) {
                         if (strtolower($object->attribute) == 'filename') {
                             $attachments[$emailId][$i]['is_attachment'] = true;
                             $attachments[$emailId][$i]['filename'] = $object->value;
                         }
                     }
                 }
                 if ($structure->parts[$i]->ifparameters) {
                     foreach ($structure->parts[$i]->parameters as $object) {
                         if (strtolower($object->attribute) == 'name') {
                             $attachments[$emailId][$i]['is_attachment'] = true;
                             $attachments[$emailId][$i]['name'] = $object->value;
                         }
                     }
                 }
                 if ($attachments[$emailId][$i]['is_attachment']) {
                     $attachments[$emailId][$i]['attachment'] = imap_fetchbody($connection, $emailId, $i + 1, FT_UID | FT_PEEK);
                     if ($structure->parts[$i]->encoding == 3) {
                         $attachments[$emailId][$i]['attachment'] = base64_decode($attachments[$emailId][$i]['attachment']);
                     } elseif ($structure->parts[$i]->encoding == 4) {
                         $attachments[$emailId][$i]['attachment'] = quoted_printable_decode($attachments[$emailId][$i]['attachment']);
                     }
                 }
             }
         }
         /* iterate through each attachment and save it */
         foreach ($attachments[$emailId] as $attachment) {
             if ($attachment['is_attachment'] == 1) {
                 $filename = $attachment['name'];
                 if (empty($filename)) {
                     $filename = $attachment['filename'];
                 }
                 if (strpos($filename, '.xls') !== false || strpos($filename, '.pdf') !== false) {
                     $onlineAdminsEmails = $this->getOnlineAdminsEmails();
                     if (!empty($onlineAdminsEmails)) {
                         $customerAlertsManager = CustomerAlertsManager::getInstance(null, null);
                         foreach ($onlineAdminsEmails as $adminEmail) {
                             $customerAlertsManager->addNewEmailFromCompanyAlert($adminEmail, $companyName);
                         }
                     }
                     break;
                 }
                 /* $filename = $attachment['name'];
                                       if (empty($filename))
                                       $filename = $attachment['filename'];
                                       if (empty($filename))
                                       $filename = time() . ".dat";
                 
                                       $fp = fopen($emailId . "-" . $filename, "w+");
                                       fwrite($fp, $attachment['attachment']);
                                       fclose($fp); */
             }
         }
     }
     return true;
 }
 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);
     }
 }
Ejemplo n.º 7
0
defined('__DIR__') or define('__DIR__', dirname(__FILE__));
$_dir = str_replace("/bin", "", __DIR__);
require_once $_dir . "/conf/constants.php";
require_once CLASSES_PATH . "/util/db/DBMSFactory.class.php";
require_once CLASSES_PATH . "/managers/OnlineUsersManager.class.php";
require_once CLASSES_PATH . "/managers/CustomerAlertsManager.class.php";
require_once CLASSES_PATH . "/managers/CompanyItemCheckListManager.class.php";
require_once CLASSES_PATH . "/managers/CmsSearchRequestsManager.class.php";
require_once CLASSES_PATH . "/managers/CbaRatesManager.class.php";
require_once CLASSES_PATH . "/managers/ReceiveEmailManager.class.php";
$config = parse_ini_file(CONF_PATH . "/config.ini");
DBMSFactory::init($config);
$onlineUsersManager = new OnlineUsersManager($config, null);
$onlineUsersManager->removeTimeOutedUsers(120);
//2 minutes
$customerAlertsManager = new CustomerAlertsManager($config, null);
$customerAlertsManager->removeOldAlerts(10);
//10 minute
$companyItemCheckListManager = new CompanyItemCheckListManager($config, null);
$companyItemCheckListManager->removeOldRowsBySeconds(120);
//2 minutes
$requestHistoryManager = new RequestHistoryManager($config, null);
$requestHistoryManager->removeOldRowsByDays(90);
// 90 days
$cmsSearchRequestsManager = new CmsSearchRequestsManager($config, null);
$cmsSearchRequestsManager->removeOldRowsByDays(90);
// 90 days
//chaching cba rates for all exchanges
$rates = getCbaRates();
if ($rates !== false) {
    $datetime = $rates[1];