Update copyright date for 2020
[civicrm-core.git] / CRM / Contact / Form / Task / PDF.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2020
32 */
33
34 /**
35 * This class provides the functionality to create PDF letter for a group of contacts or a single contact.
36 */
37 class CRM_Contact_Form_Task_PDF extends CRM_Contact_Form_Task {
38
39 /**
40 * All the existing templates in the system.
41 *
42 * @var array
43 */
44 public $_templates = NULL;
45
46 public $_single = NULL;
47
48 public $_cid = NULL;
49
50 public $_activityId = NULL;
51
52 /**
53 * Build all the data structures needed to build the form.
54 */
55 public function preProcess() {
56
57 $this->skipOnHold = $this->skipDeceased = FALSE;
58 CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
59
60 // store case id if present
61 $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'CommaSeparatedIntegers', $this, FALSE);
62 if (!empty($this->_caseId) && strpos($this->_caseId, ',')) {
63 $this->_caseIds = explode(',', $this->_caseId);
64 unset($this->_caseId);
65 }
66
67 // retrieve contact ID if this is 'single' mode
68 $cid = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this, FALSE);
69
70 if ($cid) {
71 // this is true in non-search context / single mode
72 // in search context 'id' is the default profile id for search display
73 // CRM-11227
74 $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
75 }
76
77 if ($cid) {
78 CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
79 $this->_single = TRUE;
80 }
81 else {
82 parent::preProcess();
83 }
84 $this->assign('single', $this->_single);
85 }
86
87 /**
88 * Set default values for the form.
89 */
90 public function setDefaultValues() {
91 $defaults = [];
92 if (isset($this->_activityId)) {
93 $params = ['id' => $this->_activityId];
94 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
95 $defaults['html_message'] = CRM_Utils_Array::value('details', $defaults);
96 }
97 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
98 return $defaults;
99 }
100
101 /**
102 * Build the form object.
103 */
104 public function buildQuickForm() {
105 //enable form element
106 $this->assign('suppressForm', FALSE);
107 CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
108 }
109
110 /**
111 * Process the form after the input has been submitted and validated.
112 */
113 public function postProcess() {
114 CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
115 }
116
117 /**
118 * List available tokens for this form.
119 *
120 * @return array
121 */
122 public function listTokens() {
123 $tokens = CRM_Core_SelectValues::contactTokens();
124 if (isset($this->_caseId) || isset($this->_caseIds)) {
125 // For a single case, list tokens relevant for only that case type
126 $caseTypeId = isset($this->_caseId) ? CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $this->_caseId, 'case_type_id') : NULL;
127 $tokens += CRM_Core_SelectValues::caseTokens($caseTypeId);
128 }
129 return $tokens;
130 }
131
132 }