3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Main page for viewing Notes.
21 class CRM_Contact_Page_View_Note
extends CRM_Core_Page
{
24 * Notes found running the browse function
30 * View details of a note.
32 public function view() {
33 $note = new CRM_Core_DAO_Note();
34 $note->id
= $this->_id
;
35 if ($note->find(TRUE)) {
37 CRM_Core_DAO
::storeValues($note, $this->values
);
38 $this->values
['privacy'] = CRM_Core_PseudoConstant
::getLabel('CRM_Core_BAO_Note', 'privacy', $this->values
['privacy']);
39 $this->assign('note', $this->values
);
42 $comments = CRM_Core_BAO_Note
::getNoteTree($this->values
['id'], 1);
43 if (!empty($comments)) {
44 $this->assign('comments', $comments);
47 // add attachments part
48 $currentAttachmentInfo = CRM_Core_BAO_File
::getEntityFile('civicrm_note', $this->_id
);
49 $this->assign('currentAttachmentInfo', $currentAttachmentInfo);
54 * called when action is browse.
56 public function browse() {
57 $note = new CRM_Core_DAO_Note();
58 $note->entity_table
= 'civicrm_contact';
59 $note->entity_id
= $this->_contactId
;
61 $note->orderBy('modified_date desc');
63 //CRM-4418, handling edit and delete separately.
64 $permissions = [$this->_permission
];
65 if ($this->_permission
== CRM_Core_Permission
::EDIT
) {
66 //previously delete was subset of edit
67 //so for consistency lets grant delete also.
68 $permissions[] = CRM_Core_Permission
::DELETE
;
70 $mask = CRM_Core_Action
::mask($permissions);
72 $this->assign('canAddNotes', CRM_Core_Permission
::check('add contact notes'));
74 $links = self
::links();
75 $action = array_sum(array_keys($links)) & $mask;
78 while ($note->fetch()) {
79 if (!CRM_Core_BAO_Note
::getNotePrivacyHidden($note)) {
80 CRM_Core_DAO
::storeValues($note, $this->values
[$note->id
]);
82 $this->values
[$note->id
]['action'] = CRM_Core_Action
::formLink($links,
86 'cid' => $this->_contactId
,
94 if (!empty($note->contact_id
)) {
95 $contact = new CRM_Contact_DAO_Contact();
96 $contact->id
= $note->contact_id
;
99 $this->values
[$note->id
]['createdBy'] = $contact->display_name
;
101 $this->values
[$note->id
]['comment_count'] = CRM_Core_BAO_Note
::getChildCount($note->id
);
103 // paper icon view for attachments part
104 $paperIconAttachmentInfo = CRM_Core_BAO_File
::paperIconAttachment('civicrm_note', $note->id
);
105 $this->values
[$note->id
]['attachment'] = $paperIconAttachmentInfo;
108 $this->assign('notes', $this->values
);
110 $commentLinks = self
::commentLinks();
112 $action = array_sum(array_keys($commentLinks)) & $mask;
114 $commentAction = CRM_Core_Action
::formLink($commentLinks,
118 'pid' => $note->entity_id
,
119 'cid' => $note->entity_id
,
123 'note.comment.action',
127 $this->assign('commentAction', $commentAction);
129 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('note', $this->_contactId
);
133 * called when action is update or new.
135 public function edit() {
136 $controller = new CRM_Core_Controller_Simple('CRM_Note_Form_Note', ts('Contact Notes'), $this->_action
);
137 $controller->setEmbedded(TRUE);
139 // set the userContext stack
140 $session = CRM_Core_Session
::singleton();
141 $url = CRM_Utils_System
::url('civicrm/contact/view',
142 'action=browse&selectedChild=note&cid=' . $this->_contactId
144 $session->pushUserContext($url);
146 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean')) {
148 CRM_Utils_System
::redirect($url);
151 $controller->reset();
152 $controller->set('entityTable', 'civicrm_contact');
153 $controller->set('entityId', $this->_contactId
);
154 $controller->set('id', $this->_id
);
156 $controller->process();
160 public function preProcess() {
161 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
163 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
164 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
167 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
168 $this->assign('contactId', $this->_contactId
);
170 // check logged in url permission
171 CRM_Contact_Page_View
::checkUserPermission($this);
173 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
174 CRM_Utils_System
::setTitle(ts('Notes for') . ' ' . $displayName);
176 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
177 $this->assign('action', $this->_action
);
181 * the main function that is called when the page loads,
182 * it decides the which action has to be taken for the page.
186 public function run() {
189 if ($this->_action
& CRM_Core_Action
::VIEW
) {
192 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
194 $this->_permission
!= CRM_Core_Permission
::EDIT
&&
195 !CRM_Core_Permission
::check('add contact notes')
197 CRM_Core_Error
::statusBounce(ts('You do not have access to add notes.'));
202 elseif ($this->_action
& CRM_Core_Action
::UPDATE
) {
203 if ($this->_permission
!= CRM_Core_Permission
::EDIT
) {
204 CRM_Core_Error
::statusBounce(ts('You do not have access to edit this note.'));
209 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
210 if ($this->_permission
!= CRM_Core_Permission
::EDIT
) {
211 CRM_Core_Error
::statusBounce(ts('You do not have access to delete this note.'));
213 // we use the edit screen the confirm the delete
218 return parent
::run();
222 * Delete the note object from the db and set a status msg.
224 public function delete() {
225 CRM_Core_BAO_Note
::deleteRecord(['id' => $this->_id
]);
226 $status = ts('Selected Note has been deleted successfully.');
227 CRM_Core_Session
::setStatus($status, ts('Deleted'), 'success');
235 public static function links() {
237 CRM_Core_Action
::VIEW
=> [
238 'name' => ts('View'),
239 'url' => 'civicrm/contact/view/note',
240 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
241 'title' => ts('View Note'),
243 CRM_Core_Action
::UPDATE
=> [
244 'name' => ts('Edit'),
245 'url' => 'civicrm/contact/view/note',
246 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
247 'title' => ts('Edit Note'),
249 CRM_Core_Action
::ADD
=> [
250 'name' => ts('Comment'),
251 'url' => 'civicrm/contact/view/note',
252 'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
253 'title' => ts('Add Comment'),
255 CRM_Core_Action
::DELETE
=> [
256 'name' => ts('Delete'),
257 'url' => 'civicrm/contact/view/note',
258 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
259 'title' => ts('Delete Note'),
265 * Get action links for comments.
269 public static function commentLinks() {
271 CRM_Core_Action
::VIEW
=> [
272 'name' => ts('View'),
273 'url' => 'civicrm/contact/view/note',
274 'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
275 'title' => ts('View Comment'),
277 CRM_Core_Action
::UPDATE
=> [
278 'name' => ts('Edit'),
279 'url' => 'civicrm/contact/view/note',
280 'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
281 'title' => ts('Edit Comment'),
283 CRM_Core_Action
::DELETE
=> [
284 'name' => ts('Delete'),
285 'url' => 'civicrm/contact/view/note',
286 'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
287 'title' => ts('Delete Comment'),