Merge pull request #19463 from colemanw/removeCampaignPseudoconstant
[civicrm-core.git] / CRM / Mailing / Page / AJAX.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * This class contains all the function that are called using AJAX
20 */
21class CRM_Mailing_Page_AJAX {
22
5f68c8c8
TO
23 /**
24 * Kick off the "Add Mail Account" process for some given type of account.
25 *
26 * Ex: 'civicrm/ajax/setupMailAccount?type=standard'
27 * Ex: 'civicrm/ajax/setupMailAccount?type=oauth_1'
28 *
29 * @see CRM_Core_BAO_MailSettings::getSetupActions()
30 * @throws \CRM_Core_Exception
31 */
32 public static function setup() {
33 $type = CRM_Utils_Request::retrieve('type', 'String');
34 $setupActions = CRM_Core_BAO_MailSettings::getSetupActions();
35 $setupAction = $setupActions[$type] ?? NULL;
36 if ($setupAction === NULL) {
37 throw new \CRM_Core_Exception("Cannot setup mail account. Invalid type requested.");
38 }
39
40 $result = call_user_func($setupAction['callback'], $setupAction);
41 if (isset($result['url'])) {
42 CRM_Utils_System::redirect($result['url']);
43 }
44 else {
45 throw new \CRM_Core_Exception("Cannot setup mail account. Setup does not have a URL.");
46 }
47 }
48
6a488035 49 /**
100fef9d 50 * Fetch the template text/html messages
6a488035 51 */
7c006637 52 public static function template() {
6a488035
TO
53 $templateId = CRM_Utils_Type::escape($_POST['tid'], 'Integer');
54
c6327d7d 55 $messageTemplate = new CRM_Core_DAO_MessageTemplate();
6a488035
TO
56 $messageTemplate->id = $templateId;
57 $messageTemplate->selectAdd();
58 $messageTemplate->selectAdd('msg_text, msg_html, msg_subject, pdf_format_id');
59 $messageTemplate->find(TRUE);
be2fb01f 60 $messages = [
6a488035
TO
61 'subject' => $messageTemplate->msg_subject,
62 'msg_text' => $messageTemplate->msg_text,
63 'msg_html' => $messageTemplate->msg_html,
64 'pdf_format_id' => $messageTemplate->pdf_format_id,
be2fb01f 65 ];
6a488035 66
90a73810 67 $documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $templateId);
68 foreach ((array) $documentInfo as $info) {
00eb08cf 69 list($messages['document_body']) = CRM_Utils_PDF_Document::docReader($info['fullPath'], $info['mime_type']);
90a73810 70 }
71
ecdef330 72 CRM_Utils_JSON::output($messages);
6a488035 73 }
553f116a
KJ
74
75 /**
fe482240 76 * Retrieve contact mailings.
553f116a 77 */
7c006637 78 public static function getContactMailings() {
9c3f979f 79 $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
be2fb01f 80 $params += CRM_Core_Page_AJAX::validateParams(['contact_id' => 'Integer']);
553f116a
KJ
81
82 // get the contact mailings
83 $mailings = CRM_Mailing_BAO_Mailing::getContactMailingSelector($params);
84
41348d61 85 CRM_Utils_JSON::output($mailings);
553f116a 86 }
96025800 87
6a488035 88}