from(Qs_Db::getPair('Admin', 'a'), ['email']); $select->join(Qs_Db::getPair('AdminAcl', 'acl'), '`a`.`id` = `acl`.`adminId`', []); $select->where('`a`.`email` IS NOT NULL'); $select->where('`a`.`type` = ?', App_Admin_Obj::TYPE_ADMIN); $select->where('`acl`.`aclResourceId` = ?', App_Admin_Acl::ACL_LICENSING_ID); return Qs_Db::getInstance()->fetchCol($select, ['email']); } public static function getTribalAccountEmails() { $select = Qs_Db::getSelect(); $select->from(Qs_Db::getPair('Admin', 'a'), ['email']); $select->join(Qs_Db::getPair('TribalAccountAcl', 'acl'), '`a`.`id` = `acl`.`adminId`', []); $select->where('`a`.`type` = ?', App_Admin_Obj::TYPE_TRIBAL_ACCOUNT); $select->where('`a`.`status` = ?', App_Admin_Obj::STATUS_ACTIVE); $select->where('`a`.`email` IS NOT NULL'); $select->where('`acl`.`aclResourceId` IN (?)', [ TribalAccountAcl::ACL_LICENSES_READ_ID, TribalAccountAcl::ACL_LICENSES_READ_APPROVE_ID, TribalAccountAcl::ACL_LICENSES_READ_APPROVE_DECLINE_ID, ]); $select->group('a.id'); return Qs_Db::getInstance()->fetchCol($select, ['email']); } public static function sendEmails($templateName, $placeholders) { //Send to General $toGeneral = App_Settings_Obj::getAdminEmails(); if ($toGeneral) { Qs_Mail::sendTemplate($templateName, $placeholders, $toGeneral); } //Send to Admins $toAdmins = self::getAdminEmails(); foreach ($toAdmins as $toAdmin) { Qs_Mail::sendTemplate($templateName, $placeholders, $toAdmin); } //Send to Tribal Accounts $aliasParts = explode('/', LicenseAdminView::getPage('fullAlias')); $aliasParts[0] = 'tribal-admin'; $pageUrl = BASE_URL_LANGUAGE . '/' . implode('/', $aliasParts); $placeholders['detailsUrl'] = $pageUrl . '?action=view&id=' . $placeholders['id']; $toTribalAccounts = self::getTribalAccountEmails(); foreach ($toTribalAccounts as $toTribalAccount) { Qs_Mail::sendTemplate($templateName, $placeholders, $toTribalAccount); } } public static function sendLicenseSubmittedToAdmin($licenseId) { $license = (new Model())->find(['id' => $licenseId]); $vendor = (new VendorModel())->get(['id' => $license['vendorId']], VendorModel::MAIN_DATA); $placeholders = [ 'id' => $license['id'], 'vendorDbaName' => htmlspecialchars($vendor['dbaName']), 'vendorSoleProprietorName' => htmlspecialchars($vendor['soleProprietorName']), 'vendorFederalId' => htmlspecialchars($vendor['federalId']), 'vendorPhone' => htmlspecialchars($vendor['phone']), 'detailsUrl' => LicenseAdminView::getPage('url') . '?action=view&id=' . $license['id'], ]; self::sendEmails('licenseSubmittedAdmin', $placeholders); } public static function sendLicenseSubmittedToBackgroundScreeningCompany($licenseId) { $template = 'bgScreeningToBgCompany'; if (!($to = App_Settings_Obj::getFormEmails($template . 'To', false))) { return false; } $license = (new Model())->find(['id' => $licenseId]); $vendor = (new VendorModel())->get(['id' => $license['vendorId']], VendorModel::MAIN_DATA); $placeholders = [ 'id' => $license['id'], 'vendorDbaName' => htmlspecialchars($vendor['dbaName']), 'vendorSoleProprietorName' => htmlspecialchars($vendor['soleProprietorName']), 'vendorSoleProprietorDlNumber' => htmlspecialchars($vendor['soleProprietorDlNumber']), 'vendorSoleProprietorDlStateTitle' => htmlspecialchars($vendor['soleProprietorDlStateTitle']), 'vendorFederalId' => htmlspecialchars($vendor['federalId']), 'vendorPhone' => htmlspecialchars($vendor['phone']), 'detailsUrl' => LicenseAdminView::getPage('url') . '?action=view&id=' . $license['id'], ]; return Qs_Mail::sendTemplate($template, $placeholders, $to); } public static function sendLicenseSubmittedToUser($licenseId) { return self::sendLicenseTemplateToUser($licenseId, 'licenseSubmittedUser'); } public static function sendLicenseApprovedToUser($licenseId, array $tribeIds = []) { return self::sendLicenseTemplateToUser($licenseId, 'licenseApprovedUser', $tribeIds); } public static function sendLicenseDeclinedToUser($licenseId, array $tribeIds = []) { return self::sendLicenseTemplateToUser($licenseId, 'licenseDeclinedUser', $tribeIds); } public static function sendLicensePendingToUser($licenseId, array $tribeIds = []) { return self::sendLicenseTemplateToUser($licenseId, 'licensePendingUser', $tribeIds); } public static function sendLicenseDisabledToUser($licenseId) { return self::sendLicenseTemplateToUser($licenseId, 'licenseDisabledUser'); } protected static function sendLicenseTemplateToUser($licenseId, $template, array $tribeIds = []) { $licenseModel = new Model(['db' => Qs_Db::getInstance()]); $license = $licenseModel->find(['id' => $licenseId]); $vendorModel = new VendorModel(); if (!($to = $vendorModel->getUserEmails($license['vendorId']))) { return false; } $vendor = $vendorModel->get(['id' => $license['vendorId']], VendorModel::MAIN_DATA); $placeholders = [ 'id' => $license['id'], 'vendorDbaName' => htmlspecialchars($vendor['dbaName']), 'vendorSoleProprietorName' => htmlspecialchars($vendor['soleProprietorName']), 'vendorFederalId' => htmlspecialchars($vendor['federalId']), 'vendorPhone' => htmlspecialchars($vendor['phone']), 'detailsUrl' => LicenseUserView::getPage('url') . '?action=view&id=' . $license['id'], 'receiptUrl' => PdfView::getReceiptUrl($licenseId), ]; if ($tribeIds) { $tribes = $licenseModel->getLicenseTribes($licenseId, true); $tribes = array_combine(array_column($tribes, 'tribeId'), $tribes); foreach ($tribeIds as $tribeId) { $placeholders['tribe'] = $tribes[$tribeId]['tribeTitle']; $mail = Qs_Mail::sendTemplate($template, $placeholders, $to); } } else { $mail = Qs_Mail::sendTemplate($template, $placeholders, $to); } return $mail; } public static function sendLicenseSurchargeToUser($licenseId, array $tribeIds = []) { $licenseModel = new Model(['db' => Qs_Db::getInstance()]); $license = $licenseModel->find(['id' => $licenseId]); $vendorModel = new VendorModel(); if (!($to = $vendorModel->getUserEmails($license['vendorId']))) { return false; } $vendor = $vendorModel->get(['id' => $license['vendorId']], VendorModel::MAIN_DATA); $placeholders = [ 'id' => $license['id'], 'vendorDbaName' => htmlspecialchars($vendor['dbaName']), 'vendorSoleProprietorName' => htmlspecialchars($vendor['soleProprietorName']), 'vendorFederalId' => htmlspecialchars($vendor['federalId']), 'vendorPhone' => htmlspecialchars($vendor['phone']), 'detailsUrl' => LicenseUserView::getPage('url') . '?action=view&id=' . $license['id'], ]; $mail = false; if ($tribeIds) { $tribesData = $licenseModel->getLicenseTribes($licenseId, true); $tribes = array_combine(array_column($tribesData, 'tribeId'), $tribesData); foreach ($tribeIds as $tribeId) { $placeholders['tribe'] = $tribes[$tribeId]['tribeTitle']; $placeholders['premiumAmount'] = $tribes[$tribeId]['surcharge']; $placeholders['paymentUrl'] = LicensePremiumView::getPremiumPaymentPage($license['id'], $tribeId); $mail = Qs_Mail::sendTemplate('licenseSurchargeUser', $placeholders, $to); } } return $mail; } public static function sendLicenseRenewedToAdmin($licenseId) { $license = (new Model())->find(['id' => $licenseId]); $vendor = (new VendorModel())->get(['id' => $license['vendorId']], VendorModel::MAIN_DATA); $placeholders = [ 'id' => $license['id'], 'vendorDbaName' => htmlspecialchars($vendor['dbaName']), 'vendorSoleProprietorName' => htmlspecialchars($vendor['soleProprietorName']), 'vendorFederalId' => htmlspecialchars($vendor['federalId']), 'vendorPhone' => htmlspecialchars($vendor['phone']), 'expiredOn' => date('m/d/Y', strtotime($license['expiredOn'])), 'detailsUrl' => LicenseAdminView::getPage('url') . '?action=view&id=' . $license['id'], ]; self::sendEmails('licenseRenewedAdmin', $placeholders); } public static function sendLicenseRenewedToUser($licenseId) { $license = (new Model())->find(['id' => $licenseId]); $vendorModel = new VendorModel(); if (!($to = $vendorModel->getUserEmails($license['vendorId']))) { return false; } $vendor = $vendorModel->get(['id' => $license['vendorId']], VendorModel::MAIN_DATA); $placeholders = [ 'id' => $license['id'], 'vendorDbaName' => htmlspecialchars($vendor['dbaName']), 'vendorSoleProprietorName' => htmlspecialchars($vendor['soleProprietorName']), 'vendorFederalId' => htmlspecialchars($vendor['federalId']), 'vendorPhone' => htmlspecialchars($vendor['phone']), 'expiredOn' => date('m/d/Y', strtotime($license['expiredOn'])), 'detailsUrl' => LicenseUserView::getPage('url') . '?action=view&id=' . $license['id'], ]; return Qs_Mail::sendTemplate('licenseRenewedUser', $placeholders, $to); } public static function sendLicenseExpiredToUser($licenseId, $template) { $license = (new Model())->find(['id' => $licenseId]); $vendorModel = new VendorModel(); if (!($to = $vendorModel->getUserEmails($license['vendorId']))) { return false; } $vendor = $vendorModel->get(['id' => $license['vendorId']], VendorModel::MAIN_DATA); $placeholders = [ 'id' => $license['id'], 'vendorDbaName' => htmlspecialchars($vendor['dbaName']), 'vendorSoleProprietorName' => htmlspecialchars($vendor['soleProprietorName']), 'vendorFederalId' => htmlspecialchars($vendor['federalId']), 'vendorPhone' => htmlspecialchars($vendor['phone']), 'expiredOn' => date('m/d/Y', strtotime($license['expiredOn'])), 'gracePeriod' => App_Settings_Obj::get('licenseGracePeriod'), 'licenseSectionUrl' => UserView::getPage('url'), ]; return Qs_Mail::sendTemplate($template, $placeholders, $to); } }