| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.6 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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-2014 |
| 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_Contribute_Form_Task_PDFLetter extends CRM_Contribute_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 | /** |
| 54 | * Build all the data structures needed to build the form |
| 55 | * |
| 56 | * @return void |
| 57 | */ |
| 58 | public function preProcess() { |
| 59 | $this->skipOnHold = $this->skipDeceased = FALSE; |
| 60 | CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this); |
| 61 | // store case id if present |
| 62 | $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this, FALSE); |
| 63 | |
| 64 | // retrieve contact ID if this is 'single' mode |
| 65 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE); |
| 66 | |
| 67 | $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); |
| 68 | |
| 69 | if ($cid) { |
| 70 | CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid); |
| 71 | $this->_single = TRUE; |
| 72 | $this->_cid = $cid; |
| 73 | } |
| 74 | else { |
| 75 | parent::preProcess(); |
| 76 | } |
| 77 | $this->assign('single', $this->_single); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * This virtual function is used to set the default values of |
| 82 | * various form elements |
| 83 | * |
| 84 | * access public |
| 85 | * |
| 86 | * @return array |
| 87 | * reference to the array of default values |
| 88 | */ |
| 89 | /** |
| 90 | * @return array |
| 91 | */ |
| 92 | public function setDefaultValues() { |
| 93 | $defaults = array(); |
| 94 | if (isset($this->_activityId)) { |
| 95 | $params = array('id' => $this->_activityId); |
| 96 | CRM_Activity_BAO_Activity::retrieve($params, $defaults); |
| 97 | $defaults['html_message'] = CRM_Utils_Array::value('details', $defaults); |
| 98 | } |
| 99 | else { |
| 100 | $defaults['thankyou_update'] = 1; |
| 101 | } |
| 102 | $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues(); |
| 103 | return $defaults; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Build the form object |
| 108 | * |
| 109 | * |
| 110 | * @return void |
| 111 | */ |
| 112 | public function buildQuickForm() { |
| 113 | //enable form element |
| 114 | $this->assign('suppressForm', FALSE); |
| 115 | |
| 116 | // use contact form as a base |
| 117 | CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this); |
| 118 | |
| 119 | // specific need for contributions |
| 120 | $this->add('static', 'more_options_header', NULL, ts('Thank-you Letter Options')); |
| 121 | $this->add('checkbox', 'receipt_update', ts('Update receipt dates for these contributions'), FALSE); |
| 122 | $this->add('checkbox', 'thankyou_update', ts('Update thank-you dates for these contributions'), FALSE); |
| 123 | |
| 124 | // Group options for tokens are not yet implemented. dgg |
| 125 | $options = array( |
| 126 | '' => ts('- no grouping -'), |
| 127 | 'contact_id' => ts('Contact'), |
| 128 | 'contribution_recur_id' => ts('Contact and Recurring'), |
| 129 | 'financial_type_id' => ts('Contact and Financial Type'), |
| 130 | 'campaign_id' => ts('Contact and Campaign'), |
| 131 | 'payment_instrument_id' => 'Contact and Payment Instrument', |
| 132 | ); |
| 133 | $this->addElement('select', 'group_by', ts('Group contributions by'), $options, array(), "<br/>", FALSE); |
| 134 | // this was going to be free-text but I opted for radio options in case there was a script injection risk |
| 135 | $separatorOptions = array('comma' => 'Comma', 'td' => 'Table Cell'); |
| 136 | $this->addElement('select', 'group_by_separator', ts('Separator (grouped contributions)'), $separatorOptions); |
| 137 | $emailOptions = array( |
| 138 | '' => ts('Generate PDFs for printing (only)'), |
| 139 | 'email' => ts('Send emails where possible. Generate printable PDFs for contacts who cannot receive email.'), |
| 140 | 'both' => ts('Send emails where possible. Generate printable PDFs for all contacts.'), |
| 141 | ); |
| 142 | if (CRM_Core_Config::singleton()->doNotAttachPDFReceipt) { |
| 143 | $emailOptions['pdfemail'] = ts('Send emails with an attached PDF where possible. Generate printable PDFs for contacts who cannot receive email.'); |
| 144 | $emailOptions['pdfemail_both'] = ts('Send emails with an attached PDF where possible. Generate printable PDFs for all contacts.'); |
| 145 | } |
| 146 | $this->addElement('select', 'email_options', ts('Print and email options'), $emailOptions, array(), "<br/>", FALSE); |
| 147 | |
| 148 | $this->addButtons(array( |
| 149 | array( |
| 150 | 'type' => 'submit', |
| 151 | 'name' => ts('Make Thank-you Letters'), |
| 152 | 'isDefault' => TRUE, |
| 153 | ), |
| 154 | array( |
| 155 | 'type' => 'cancel', |
| 156 | 'name' => ts('Done'), |
| 157 | ), |
| 158 | ) |
| 159 | ); |
| 160 | |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Process the form after the input has been submitted and validated |
| 165 | * |
| 166 | * |
| 167 | * @return void |
| 168 | */ |
| 169 | public function postProcess() { |
| 170 | CRM_Contribute_Form_Task_PDFLetterCommon::postProcess($this); |
| 171 | } |
| 172 | } |