Merge branch '4.6' into master
[civicrm-core.git] / CRM / Contact / Form / Task / PDF.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
32 * $Id$
33 *
34 */
35
36 /**
37 * This class provides the functionality to create PDF letter for a group of
38 * contacts or a single contact.
39 */
40 class CRM_Contact_Form_Task_PDF extends CRM_Contact_Form_Task {
41
42 /**
43 * All the existing templates in the system.
44 *
45 * @var array
46 */
47 public $_templates = NULL;
48
49 public $_single = NULL;
50
51 public $_cid = NULL;
52
53 public $_activityId = NULL;
54
55 /**
56 * Build all the data structures needed to build the form.
57 *
58 * @return void
59 */
60 public function preProcess() {
61
62 $this->skipOnHold = $this->skipDeceased = FALSE;
63 CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
64
65 // store case id if present
66 $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this, FALSE);
67
68 // retrieve contact ID if this is 'single' mode
69 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
70
71 if ($cid) {
72 // this is true in non-search context / single mode
73 // in search context 'id' is the default profile id for search display
74 // CRM-11227
75 $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
76 }
77
78 if ($cid) {
79 CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid);
80 $this->_single = TRUE;
81 $this->_cid = $cid;
82 }
83 else {
84 parent::preProcess();
85 }
86 $this->assign('single', $this->_single);
87 }
88
89 /**
90 * Set default values for the form. Relationship that in edit/view action
91 * the default values are retrieved from the database
92 *
93 *
94 * @return void
95 */
96 /**
97 */
98 public function setDefaultValues() {
99 $defaults = array();
100 if (isset($this->_activityId)) {
101 $params = array('id' => $this->_activityId);
102 CRM_Activity_BAO_Activity::retrieve($params, $defaults);
103 $defaults['html_message'] = CRM_Utils_Array::value('details', $defaults);
104 }
105 $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
106 return $defaults;
107 }
108
109 /**
110 * Build the form object.
111 *
112 *
113 * @return void
114 */
115 public function buildQuickForm() {
116 //enable form element
117 $this->assign('suppressForm', FALSE);
118 CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
119 }
120
121 /**
122 * Process the form after the input has been submitted and validated.
123 *
124 *
125 * @return void
126 */
127 public function postProcess() {
128 CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
129 }
130
131 /**
132 * List available tokens for this form.
133 *
134 * @return array
135 */
136 public function listTokens() {
137 $tokens = CRM_Core_SelectValues::contactTokens();
138 return $tokens;
139 }
140
141 }