3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * This class generates form components generic to note
39 * It delegates the work to lower level subclasses and integrates the changes
40 * back in. It also uses a lot of functionality with the CRM API's, so any change
41 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
44 class CRM_Note_Form_Note
extends CRM_Core_Form
{
47 * The table name, used when editing/creating a note
51 protected $_entityTable;
54 * The table id, used when editing/creating a note
61 * The note id, used when editing the note
68 * The parent note id, used when adding a comment to a note
74 function preProcess() {
75 $this->_entityTable
= $this->get('entityTable');
76 $this->_entityId
= $this->get('entityId');
77 $this->_id
= $this->get('id');
78 $this->_parentId
= CRM_Utils_Array
::value('parentId', $_GET, 0);
79 if ($this->_parentId
) {
80 $this->assign('parentId', $this->_parentId
);
83 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
84 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
87 // set title to "Note - " + Contact Name
88 $displayName = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_entityId
, 'display_name');
89 $pageTitle = 'Note - ' . $displayName;
90 $this->assign('pageTitle', $pageTitle);
94 * This function sets the default values for the form. Note that in edit/view mode
95 * the default values are retrieved from the database
101 function setDefaultValues() {
104 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
105 if (isset($this->_id
)) {
106 $params['id'] = $this->_id
;
107 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_Note', $params, $defaults);
109 if ($defaults['entity_table'] == 'civicrm_note') {
110 $defaults['parent_id'] = $defaults['entity_id'];
113 elseif ($this->_action
& CRM_Core_Action
::ADD
&& $this->_parentId
) {
114 $defaults['parent_id'] = $this->_parentId
;
115 $defaults['subject'] = 'Re: ' . CRM_Core_BAO_Note
::getNoteSubject($this->_parentId
);
121 * Function to actually build the form
126 public function buildQuickForm() {
127 if ($this->_action
& CRM_Core_Action
::DELETE
) {
128 $this->addButtons(array(
131 'name' => ts('Delete'),
136 'name' => ts('Cancel'),
143 $this->add('text', 'subject', ts('Subject:'), array('size' => 20));
144 $this->add('textarea', 'note', ts('Note:'), CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Note', 'note'), TRUE);
145 $this->add('select', 'privacy', ts('Privacy:'), CRM_Core_OptionGroup
::values('note_privacy'));
147 $this->add('hidden', 'parent_id');
149 // add attachments part
150 CRM_Core_BAO_File
::buildAttachment($this, 'civicrm_note', $this->_id
, NULL, TRUE);
152 $this->addButtons(array(
155 'name' => ts('Save'),
160 'name' => ts('Cancel'),
172 public function postProcess() {
173 // store the submitted values in an array
174 $params = $this->controller
->exportValues($this->_name
);
176 $session = CRM_Core_Session
::singleton();
177 $params['contact_id'] = $session->get('userID');
179 if ($params['parent_id']) {
180 $params['entity_table'] = 'civicrm_note';
181 $params['entity_id'] = $params['parent_id'];
184 $params['entity_table'] = $this->_entityTable
;
185 $params['entity_id'] = $this->_entityId
;
188 if ($this->_action
& CRM_Core_Action
::DELETE
) {
189 CRM_Core_BAO_Note
::del($this->_id
);
193 $params['id'] = null;
194 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
195 $params['id'] = $this->_id
;
198 // add attachments as needed
199 CRM_Core_BAO_File
::formatAttachment($params, $params, 'civicrm_note', $params['id']);
202 $note = CRM_Core_BAO_Note
::add($params, $ids);
204 CRM_Core_Session
::setStatus(ts('Your Note has been saved.'), ts('Saved'), 'success');