| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.5 | |
| 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 | * @access public |
| 58 | */ |
| 59 | function preProcess() { |
| 60 | $this->skipOnHold = $this->skipDeceased = FALSE; |
| 61 | CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this); |
| 62 | |
| 63 | // store case id if present |
| 64 | $this->_caseId = CRM_Utils_Request::retrieve('caseid', 'Positive', $this, FALSE); |
| 65 | |
| 66 | // retrieve contact ID if this is 'single' mode |
| 67 | $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE); |
| 68 | |
| 69 | $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); |
| 70 | |
| 71 | if ($cid) { |
| 72 | CRM_Contact_Form_Task_PDFLetterCommon::preProcessSingle($this, $cid); |
| 73 | $this->_single = TRUE; |
| 74 | $this->_cid = $cid; |
| 75 | } |
| 76 | else { |
| 77 | parent::preProcess(); |
| 78 | } |
| 79 | $this->assign('single', $this->_single); |
| 80 | } |
| 81 | |
| 82 | function setDefaultValues() { |
| 83 | $defaults = array(); |
| 84 | if (isset($this->_activityId)) { |
| 85 | $params = array('id' => $this->_activityId); |
| 86 | CRM_Activity_BAO_Activity::retrieve($params, $defaults); |
| 87 | $defaults['html_message'] = CRM_Utils_Array::value('details', $defaults); |
| 88 | } |
| 89 | else { |
| 90 | $defaults['thankyou_update'] = 1; |
| 91 | } |
| 92 | $defaults = $defaults + CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues(); |
| 93 | return $defaults; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Build the form |
| 98 | * |
| 99 | * @access public |
| 100 | * |
| 101 | * @return void |
| 102 | */ |
| 103 | public function buildQuickForm() { |
| 104 | //enable form element |
| 105 | $this->assign('suppressForm', FALSE); |
| 106 | |
| 107 | // use contact form as a base |
| 108 | CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this); |
| 109 | |
| 110 | // specific need for contributions |
| 111 | $this->add('static', 'more_options_header', NULL, ts('Record Update Options')); |
| 112 | $this->add('checkbox', 'receipt_update', ts('Update receipt dates for these contributions'), FALSE); |
| 113 | $this->add('checkbox', 'thankyou_update', ts('Update thank-you dates for these contributions'), FALSE); |
| 114 | |
| 115 | // Group options for tokens are not yet implemented. dgg |
| 116 | $options = array(ts('Contact'), ts('Recurring')); |
| 117 | $this->addRadio('is_group_by', ts('Grouping contributions in one letter based on'), $options, array('allowClear' => TRUE), "<br/>", FALSE); |
| 118 | |
| 119 | $this->addButtons(array( |
| 120 | array( |
| 121 | 'type' => 'submit', |
| 122 | 'name' => ts('Make Thank-you Letters'), |
| 123 | 'isDefault' => TRUE, |
| 124 | ), |
| 125 | array( |
| 126 | 'type' => 'cancel', |
| 127 | 'name' => ts('Done'), |
| 128 | ), |
| 129 | ) |
| 130 | ); |
| 131 | |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * process the form after the input has been submitted and validated |
| 136 | * |
| 137 | * @access public |
| 138 | * |
| 139 | * @return void |
| 140 | */ |
| 141 | public function postProcess() { |
| 142 | // TODO: rewrite using contribution token and one letter by contribution |
| 143 | $this->setContactIDs(); |
| 144 | |
| 145 | CRM_Contribute_Form_Task_PDFLetterCommon::postProcess($this); |
| 146 | } |
| 147 | } |
| 148 | |