public function service()
 {
     $userManager = new UserManager($this->config, $this->args);
     $email = strtolower($this->secure($_REQUEST["email"]));
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $jsonArr = array('status' => "err", "errText" => $this->getPhrase(471));
         echo json_encode($jsonArr);
         return false;
     }
     $customer = $userManager->getCustomerByEmail($email);
     if ($customer != null) {
         $emailSenderManager = new EmailSenderManager('gmail');
         $customerEmail = $customer->getEmail();
         $userName = $customer->getName();
         $password = $customer->getPassword();
         $subject = "Your PcStore Password!";
         $templateId = "customer_forgot_password";
         $params = array("name" => $userName, "password" => $password);
         $emailSenderManager->sendEmail('support', $customerEmail, $subject, $templateId, $params);
         $jsonArr = array('status' => "ok", "message" => "Your password sent to your " . $email . " email.\nPlease check your email.");
         echo json_encode($jsonArr);
         return true;
     } else {
         $jsonArr = array('status' => "err", "errText" => $this->getPhrase(381));
         echo json_encode($jsonArr);
         return false;
     }
 }
 private function sendStockUpdatedEmailToCompany($company_id)
 {
     $emailSenderManager = new EmailSenderManager('gmail');
     $companyManager = CompanyManager::getInstance($this->config, $this->args);
     $company = $companyManager->selectByPK($company_id);
     if (isset($company) && $company->getReceiveEmailOnStockUpdate() == 1) {
         $company_email = $company->getEmail();
         $subject = $this->getPhrase(531, 'en');
         $templateId = 'company_stock_updated';
         $params = array("support_phone" => $this->getCmsVar('pcstore_support_phone_number'));
         $emailSenderManager->sendEmail('info', $company_email, $subject, $templateId, $params);
     }
 }
 public function service()
 {
     $userManager = new UserManager($this->config, $this->args);
     $email = strtolower($this->secure($_REQUEST["email"]));
     $name = $this->secure($_REQUEST["name"]);
     $phone = $this->secure($_REQUEST["phone"]);
     $pass = $this->secure($_REQUEST["pass"]);
     $invitation_code = $this->secure($_COOKIE["invc"]);
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $jsonArr = array('status' => "err", "errText" => $this->getPhraseSpan(471));
         echo json_encode($jsonArr);
         return false;
     }
     $custDto = $userManager->getCustomerByEmail($email);
     if ($custDto) {
         $jsonArr = array('status' => "err", "errText" => $this->getPhraseSpan(359));
         echo json_encode($jsonArr);
         return false;
     }
     if (!$userManager->checkPassword($pass)) {
         $jsonArr = array('status' => "err", "errText" => $this->getPhraseSpan(358));
         echo json_encode($jsonArr);
         return false;
     }
     if (!$name || strlen($name) == 0) {
         $jsonArr = array('status' => "err", "errText" => $this->getPhraseSpan(356));
         echo json_encode($jsonArr);
         return false;
     }
     if ($phone != null) {
         if (strpos($phone, ',') !== false) {
             $jsonArr = array('status' => "err", "errText" => $this->getPhraseSpan(521));
             echo json_encode($jsonArr);
             return false;
         }
     }
     $userId = $userManager->createUser($email, $pass, $name, $phone);
     $userManager->setSubUser($invitation_code, $userId, $email);
     $userDto = $userManager->selectByPK($userId);
     //sending activation email using $userDto->getActivationCode();
     $emailSenderManager = new EmailSenderManager('gmail');
     $username = $name;
     $subject = "PcStore Activation!";
     $activation_code = $userDto->getActivationCode();
     $template = "account_activation";
     $params = array("user_name" => $username, "activation_code" => $activation_code);
     $emailSenderManager->sendEmail('registration', $email, $subject, $template, $params);
     $jsonArr = array('status' => "ok");
     echo json_encode($jsonArr);
     return true;
 }
 public function service()
 {
     $emailSenderManager = new EmailSenderManager('gmail');
     $email = strtolower($this->secure($_REQUEST['email']));
     $msg = $this->secure($_REQUEST['msg']);
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         $jsonArr = array('status' => "err", "message" => $this->getPhraseSpan(471));
         echo json_encode($jsonArr);
         return false;
     }
     $pcstore_contact_us_email = $this->getCmsVar('pcstore_contact_us_email');
     $subject = "Message To PcStore from " . $email;
     $templateId = "contact_us";
     $params = array("msg" => $msg);
     if ($this->getUserLevel() !== UserGroups::$GUEST) {
         $fromName = $this->getCustomer()->getName() . ' (' . $this->getUserLevelString() . '-' . $this->getUserId() . ')';
     } else {
         $fromName = $email;
     }
     $emailSenderManager->sendEmail('contactus', $pcstore_contact_us_email, $subject, $templateId, $params, $email, $fromName);
     $jsonArr = array('status' => "ok", "message" => $this->getPhrase(438));
     echo json_encode($jsonArr);
     return true;
 }
 public function service()
 {
     $toEmails = strtolower(trim($_REQUEST['to_emails']));
     $valid_addresses = EmailSenderManager::getEmailsFromText($toEmails);
     $uninterestingEmailsManager = UninterestingEmailsManager::getInstance($this->config, $this->args);
     $valid_addresses = $uninterestingEmailsManager->removeUninterestingEmailsFromList($valid_addresses);
     //saving valis recipients
     $companyDto = $this->getCustomer();
     if (!$companyDto) {
         return false;
     }
     $companyExtendedProfileManager = CompanyExtendedProfileManager::getInstance($this->config, $this->args);
     $dto = $companyExtendedProfileManager->getByCompanyId($companyDto->getId());
     $dto->setDealerEmails(implode(';', $valid_addresses));
     $companyExtendedProfileManager->updateByPK($dto);
     $jsonArr = array('status' => "ok", "valid_email_addresses" => implode(';', $valid_addresses));
     echo json_encode($jsonArr);
     return true;
 }
 private function emailOrderDetails($orderId)
 {
     $emailSenderManager = new EmailSenderManager('gmail');
     $customer = $this->getCustomer();
     $userManager = UserManager::getInstance($this->config, $this->args);
     $customerEmail = $userManager->getRealEmailAddressByUserDto($customer);
     $emailAccountsManager = EmailAccountsManager::getInstance($this->config, $this->args);
     $infoEmailAddress = $emailAccountsManager->getEmailAddressById('info');
     $recipients = array($customerEmail, $infoEmailAddress);
     $lname = $customer->getLastName();
     $userName = $customer->getName();
     if (isset($lname)) {
         $userName .= ' ' . $lname;
     }
     $orderJoinedDetailsDtos = $this->ordersManager->getOrderJoinedWithDetails($orderId);
     $goupedOrderJoinedDetailsDtos = $this->groupBundlesInOrderJoinedDetailsDtos($orderJoinedDetailsDtos);
     $paymentType = $orderJoinedDetailsDtos[0]->getPaymentType();
     $payment_option_values = explode(',', $this->getCmsVar('payment_option_values'));
     $payment_options_display_names_ids = explode(',', $this->getCmsVar('payment_options_display_names_ids'));
     $index = array_search($paymentType, $payment_option_values);
     $paymentTypeDisplayNameId = $payment_options_display_names_ids[$index];
     $subject = $this->getPhrase(299);
     if ($paymentType == 'credit') {
         $template = "customer_credit_order";
     } else {
         $template = "customer_cash_order";
     }
     $params = array("user_name" => $userName, "dtos" => $goupedOrderJoinedDetailsDtos, "itemManager" => $this->itemManager, "support_phone" => $this->getCmsVar('pcstore_support_phone_number'), 'paymentTypeDisplayNameId' => $paymentTypeDisplayNameId);
     if ($paymentType == 'credit') {
         $creditSuppliersManager = CreditSuppliersManager::getInstance($this->config, $this->args);
         $csid = $orderJoinedDetailsDtos[0]->getCreditOrdersCreditSupplierId();
         $creditSupplierDto = $creditSuppliersManager->selectByPK($csid);
         $commission = $creditSupplierDto->getCommission();
         $grandTotalAMD = intval($orderJoinedDetailsDtos[0]->getOrderTotalAmd());
         $grandTotalAmdWithCommission = intval($grandTotalAMD / (1 - $commission / 100));
         $params['grandTotalAmdWithCommission'] = $grandTotalAmdWithCommission;
     }
     $emailSenderManager->sendEmail('orders', $recipients, $subject, $template, $params, '', '', true, false);
 }
 public function service()
 {
     $userManager = UserManager::getInstance($this->config, $this->args);
     $userPendingSubUsersManager = new UserPendingSubUsersManager($this->config, $this->args);
     $emailSenderManager = new EmailSenderManager('gmail');
     $userId = $this->getUserId();
     $user = $userManager->selectByPK($userId);
     $subUsersRegistrationCode = $user->getSubUsersRegistrationCode();
     if ($subUsersRegistrationCode == null || strlen($subUsersRegistrationCode) == 0) {
         $subUsersRegistrationCode = uniqid();
         $userManager->setSubUsersRegistrationCode($userId, $subUsersRegistrationCode);
     }
     if (isset($_REQUEST["emails"])) {
         $emails = $this->secure($_REQUEST["emails"]);
         $emailsArray = explode(',', $emails);
         $validEmailToBeInvited = array();
         foreach ($emailsArray as $email) {
             if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
                 $customerByEmail = $userManager->getCustomerByEmail($email);
                 if (!isset($customerByEmail)) {
                     $byUserIdAndPendingSubUserEmail = $userPendingSubUsersManager->getByUserIdAndPendingSubUserEmail($userId, $email);
                     if (!isset($byUserIdAndPendingSubUserEmail)) {
                         $userPendingSubUsersManager->addPendingSubUserEmailToUser($email, $userId);
                         $validEmailToBeInvited[] = $email;
                     }
                 }
             }
         }
         if (count($validEmailToBeInvited) > 0) {
             $from = $userManager->getRealEmailAddress($userId);
             $username = $user->getName();
             $subject = $username . " invites you to join PcStore!";
             $template = "user_to_user_invitation";
             $params = array("user_name" => $username, "invitation_code" => $subUsersRegistrationCode);
             $fromName = $user->getName() . ' ' . $user->getLastName();
             $emailSenderManager->sendEmail('news', $validEmailToBeInvited, $subject, $template, $params, $from, $fromName);
         }
         $this->ok(array("message" => $this->getPhraseSpan(603)));
     } elseif (isset($_REQUEST["user_email"])) {
         $pendingUserEmail = $this->secure($_REQUEST["user_email"]);
         if (filter_var($pendingUserEmail, FILTER_VALIDATE_EMAIL)) {
             if ($userManager->getCustomerByEmail($pendingUserEmail)) {
                 $this->error(array("errText" => $this->getPhraseSpan(359)));
             }
             if (!$userPendingSubUsersManager->getByUserIdAndPendingSubUserEmail($userId, $pendingUserEmail)) {
                 $userPendingSubUsersManager->addPendingSubUserEmailToUser($pendingUserEmail, $userId);
                 //sending invitation email to user
                 $from = $userManager->getRealEmailAddress($userId);
                 $username = $user->getName();
                 $subject = $username . " invites you to join PcStore!";
                 $template = "user_to_user_invitation";
                 $params = array("user_name" => $username, "invitation_code" => $subUsersRegistrationCode);
                 $fromName = $user->getName() . ' ' . $user->getLastName();
                 $emailSenderManager->sendEmail('news', $pendingUserEmail, $subject, $template, $params, $from, $fromName);
                 $this->ok(array("message" => $this->getPhraseSpan(603)));
             } else {
                 $this->error(array("errText" => $this->getPhraseSpan(605)));
             }
         } else {
             $this->error(array("errText" => $this->getPhraseSpan(471)));
         }
     } elseif (isset($_REQUEST["invitation_id"])) {
         $invitationId = intval($_REQUEST["invitation_id"]);
         $from = $userManager->getRealEmailAddress($userId);
         $username = $user->getName();
         $subject = $username . " invites you to join PcStore!";
         $template = "user_to_user_invitation";
         $params = array("user_name" => $username, "invitation_code" => $subUsersRegistrationCode);
         $fromName = $user->getName() . ' ' . $user->getLastName();
         $dto = $userPendingSubUsersManager->selectByPK($invitationId);
         $pendingSubUserEmail = $dto->getPendingSubUserEmail();
         $emailSenderManager->sendEmail('news', $pendingSubUserEmail, $subject, $template, $params, $from, $fromName);
         $dto->setLastSent(date('Y-m-d H:i:s'));
         $userPendingSubUsersManager->updateByPk($dto);
         $this->ok(array("message" => $this->getPhraseSpan(603)));
     }
 }
 public function service()
 {
     $action = $_REQUEST['action'];
     $params = array();
     switch ($action) {
         case 'delete_user':
             $this->deleteUser($_REQUEST['user_id']);
             break;
         case 'delete_all_unnecessary_items_pictures':
             $ret = $this->deleteAllUnnecessaryItemsPictures();
             $params = array('removed_items_ids' => implode(',', $ret));
             break;
         case 'set_item_spec':
             $itemId = $_REQUEST['item_id'];
             $shortSpec = $_REQUEST['short_spec'];
             $fullSpec = $_REQUEST['full_spec'];
             require_once CLASSES_PATH . "/managers/ItemManager.class.php";
             $itemManager = ItemManager::getInstance($this->config, $this->args);
             $itemManager->updateTextField($itemId, 'short_description', $shortSpec);
             $itemManager->updateTextField($itemId, 'full_description', $fullSpec);
             break;
         case 'get_item_spec':
             $itemId = $_REQUEST['item_id'];
             require_once CLASSES_PATH . "/managers/ItemManager.class.php";
             $itemManager = ItemManager::getInstance($this->config, $this->args);
             $itemDto = $itemManager->selectByPK($itemId);
             $params['short_spec'] = $itemDto->getShortDescription();
             $params['full_spec'] = $itemDto->getFullDescription();
             break;
         case 'get_camera_1_snap':
             $url = $this->getCmsVar('pcstore_camera_1_url');
             $login = $this->getCmsVar('pcstore_camera_1_login');
             $pass = $this->getCmsVar('pcstore_camera_1_pass');
             $ch = curl_init($url);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_USERPWD, $login . ':' . $pass);
             $img = curl_exec($ch);
             header("Content-Type: image/jpeg");
             echo $img;
             exit;
         case 'filter_emails':
             require_once CLASSES_PATH . "/managers/EmailSenderManager.class.php";
             require_once CLASSES_PATH . "/managers/UninterestingEmailsManager.class.php";
             $emails = $_REQUEST['emails'];
             $emailsArray = EmailSenderManager::getEmailsFromText($emails);
             $uninterestingEmailsManager = UninterestingEmailsManager::getInstance($this->config, $this->args);
             $filteredEmailsArray = $uninterestingEmailsManager->removeUninterestingEmailsFromList($emailsArray);
             $params['count'] = count($filteredEmailsArray);
             $params['emails'] = implode(';', $filteredEmailsArray);
             break;
         case 'is_price_values_ready':
             $companyId = intval($_REQUEST['company_id']);
             require_once CLASSES_PATH . "/managers/PriceTextsManager.class.php";
             $priceTextsManager = PriceTextsManager::getInstance($this->config, $this->args);
             $companyPriceValuesReady = $priceTextsManager->isCompanyPriceValuesReady($companyId);
             $params['ready'] = $companyPriceValuesReady ? '1' : '0';
             break;
         case 'delete_price_values_column':
             $companyId = intval($_REQUEST['company_id']);
             $sheetIndex = intval($_REQUEST['sheet_index']);
             $priceIndex = intval($_REQUEST['price_index']);
             $columnLetter = $this->secure($_REQUEST['column_letter']);
             require_once CLASSES_PATH . "/managers/PriceValuesManager.class.php";
             $priceValuesManager = PriceValuesManager::getInstance($this->config, $this->args);
             $priceValuesManager->moveColumnValuesToLastColumn($companyId, $priceIndex, $sheetIndex, $columnLetter);
             break;
         case 'delete_customer_amessage_after_login':
             $pk = intval($_REQUEST['id']);
             require_once CLASSES_PATH . "/managers/CustomerMessagesAfterLoginManager.class.php";
             $customerMessagesAfterLoginManager = CustomerMessagesAfterLoginManager::getInstance($this->config, $this->args);
             $customerMessagesAfterLoginManager->deleteByPK($pk);
             break;
         case 'preview_customer_message':
             $pk = intval($_REQUEST['id']);
             require_once CLASSES_PATH . "/managers/CustomerMessagesAfterLoginManager.class.php";
             $customerMessagesAfterLoginManager = CustomerMessagesAfterLoginManager::getInstance($this->config, $this->args);
             $dto = $customerMessagesAfterLoginManager->selectByPK($pk);
             $params = AbstractDto::dtoToArray($dto);
             break;
         case 'delete_old_hidden_items':
             $monthsNumber = intval($_REQUEST['months_number']);
             require_once CLASSES_PATH . "/managers/ItemManager.class.php";
             $itemManager = ItemManager::getInstance($this->config, $this->args);
             $params['count'] = $itemManager->deleteOldHiddenItemsByMonthsNumber($monthsNumber);
             break;
         case 'update_companies_price_text':
             $company_id = intval($_REQUEST['company_id']);
             $companyManager = CompanyManager::getInstance($this->config, $this->args);
             if ($company_id == 0) {
                 $allCompanies = $companyManager->getAllCompanies(true, true);
             } else {
                 $allCompanies[] = $companyManager->selectByPK($company_id);
             }
             $cidsArray = array();
             foreach ($allCompanies as $c) {
                 $cidsArray[] = $c->getId();
             }
             $this->updateCompanyPriceText(implode(',', $cidsArray));
             break;
         case 'deploy_latest_pcstore_changes':
             $protocol = "http://";
             if (isset($_SERVER["HTTPS"])) {
                 $protocol = "https://";
             }
             $content = file_get_contents($protocol . HTTP_HOST . '/8350e5a3e24c153df2275c9f80692773.php');
             $params['message'] = $content;
             break;
     }
     $this->ok($params);
 }
 private function sendEmailToDealersEmails($companyExProfiledto, $byMandrill = false)
 {
     $dealerEmailsText = $companyExProfiledto->getDealerEmails();
     $dealerEmailsArray = explode(';', $dealerEmailsText);
     $subject = $companyExProfiledto->getPriceEmailSubject();
     $body = stripslashes($companyExProfiledto->getPriceEmailBody());
     $fromEmail = $companyExProfiledto->getFromEmail();
     $companyName = $this->getCustomer()->getName();
     $isServiceCompany = $this->getUserLevel() == UserGroups::$SERVICE_COMPANY;
     $priceFiles = array();
     if ($isServiceCompany) {
         $companiesPriceListManager = ServiceCompaniesPriceListManager::getInstance($this->config, $this->args);
         $companyId = $companyExProfiledto->getServiceCompanyId();
         $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($companyId);
         if (!empty($companyLastPrices)) {
             foreach ($companyLastPrices as $key => $clp) {
                 $priceFiles[] = DATA_DIR . "/service_companies_prices/" . $companyId . '/' . $clp->getFileName() . '.' . $clp->getFileExt();
             }
         }
         $tmpSubdirectoryName = 'service_companies';
     } else {
         $companiesPriceListManager = CompaniesPriceListManager::getInstance($this->config, $this->args);
         $companyId = $companyExProfiledto->getCompanyId();
         $companyLastPrices = $companiesPriceListManager->getCompanyLastPrices($companyId);
         if (!empty($companyLastPrices)) {
             foreach ($companyLastPrices as $key => $clp) {
                 $priceFiles[] = DATA_DIR . "/companies_prices/" . $companyId . '/' . $clp->getFileName() . '.' . $clp->getFileExt();
             }
         }
         $tmpSubdirectoryName = 'companies';
     }
     $allEmailFileAttachments = array();
     foreach ($priceFiles as $key => $priceFile) {
         $pfnParts = explode('.', $priceFile);
         $priceFileExtention = end($pfnParts);
         if (file_exists($priceFile)) {
             $postfix = "";
             if ($key > 0) {
                 $postfix = '_' . ($key + 1);
             }
             $allEmailFileAttachments[$companyName . ' Pricelist' . $postfix . '.' . $priceFileExtention] = $priceFile;
         }
     }
     $additionalAttachedFiles = array();
     $dir = HTDOCS_TMP_DIR_ATTACHMENTS . '/' . $tmpSubdirectoryName . '/' . $companyId . '/';
     if (is_dir($dir)) {
         $additionalAttachedFiles = scandir($dir);
     }
     foreach ($additionalAttachedFiles as $file) {
         $fileFullPath = $dir . $file;
         if (is_file($fileFullPath)) {
             $path_parts = pathinfo($fileFullPath);
             $basename = $path_parts['basename'];
             $fileDisplayName = substr($basename, strpos($basename, '_') + 1);
             $allEmailFileAttachments[$fileDisplayName] = $fileFullPath;
         }
     }
     if ($byMandrill == true) {
         $mandrillEmailSenderManager = new MandrillEmailSenderManager($this->getCmsVar("mandrill_api_key"));
         $body .= '<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>';
         $body .= '<p style="font-size:10px"><a href="*|UNSUB:http://pcstore.am/unsub/' . ($isServiceCompany ? 'sc' : 's') . '/' . $companyId . '|*">Click here to unsubscribe.</a></p>';
         $res = $mandrillEmailSenderManager->sendHtmlEmail($dealerEmailsArray, $subject, $body, $fromEmail, $companyName, $allEmailFileAttachments, ($isServiceCompany ? 'service_company' : 'company') . '_' . $companyId);
         $sentSuccess = is_array($res);
     } else {
         $emailSenderManager = new EmailSenderManager('gmail');
         $res = $emailSenderManager->sendBulkEmailWithAttachmentsUsingPcstoreEmails($dealerEmailsArray, $subject, $body, array(), $allEmailFileAttachments, $fromEmail, $companyName);
         $sentSuccess = $res === true;
     }
     if ($sentSuccess !== true) {
         return $res;
     } else {
         $companyPriceEmailHistoryManager = CompanyPriceEmailHistoryManager::getInstance($this->config, $this->args);
         $companyPriceEmailHistoryManager->addRow($companyId, $isServiceCompany ? "service_company" : "company", $fromEmail, $dealerEmailsArray, $body, $subject, array_keys($allEmailFileAttachments));
     }
     return true;
 }
 public function sendNewPriceUploadedEmailToCompanyDealers($company)
 {
     $companyDealersManager = CompanyDealersManager::getInstance($this->config, $this->args);
     $compayDealers = $companyDealersManager->getCompanyDealersUsersFullInfoHiddenIncluded($company->getId());
     $allUsersEmails = $this->getUsersEmailByUsersDtos($compayDealers);
     $emailSenderManager = new EmailSenderManager('gmail');
     $companyName = $company->getName();
     $subject = 'New Price form ' . $companyName . '!!!';
     $template = "new_price_uploaded";
     $params = array("company_name" => $companyName);
     $emailSenderManager->sendEmail('info', $allUsersEmails, $subject, $template, $params, '', '', true, true);
 }