3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
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-2020
35 * Main page for viewing Notes.
37 class CRM_Contact_Page_View_Note
extends CRM_Core_Page
{
40 * The action links for notes that we need to display for the browse screen
44 public static $_links = NULL;
47 * The action links for comments that we need to display for the browse screen
51 public static $_commentLinks = NULL;
54 * Notes found running the browse function
60 * View details of a note.
62 public function view() {
63 $note = new CRM_Core_DAO_Note();
64 $note->id
= $this->_id
;
65 if ($note->find(TRUE)) {
67 CRM_Core_DAO
::storeValues($note, $this->values
);
68 $this->values
['privacy'] = CRM_Core_PseudoConstant
::getLabel('CRM_Core_BAO_Note', 'privacy', $this->values
['privacy']);
69 $this->assign('note', $this->values
);
72 $comments = CRM_Core_BAO_Note
::getNoteTree($this->values
['id'], 1);
73 if (!empty($comments)) {
74 $this->assign('comments', $comments);
77 // add attachments part
78 $currentAttachmentInfo = CRM_Core_BAO_File
::getEntityFile('civicrm_note', $this->_id
);
79 $this->assign('currentAttachmentInfo', $currentAttachmentInfo);
84 * called when action is browse.
86 public function browse() {
87 $note = new CRM_Core_DAO_Note();
88 $note->entity_table
= 'civicrm_contact';
89 $note->entity_id
= $this->_contactId
;
91 $note->orderBy('modified_date desc');
93 //CRM-4418, handling edit and delete separately.
94 $permissions = [$this->_permission
];
95 if ($this->_permission
== CRM_Core_Permission
::EDIT
) {
96 //previously delete was subset of edit
97 //so for consistency lets grant delete also.
98 $permissions[] = CRM_Core_Permission
::DELETE
;
100 $mask = CRM_Core_Action
::mask($permissions);
102 $this->assign('canAddNotes', CRM_Core_Permission
::check('add contact notes'));
104 $links = self
::links();
105 $action = array_sum(array_keys($links)) & $mask;
108 while ($note->fetch()) {
109 if (!CRM_Core_BAO_Note
::getNotePrivacyHidden($note)) {
110 CRM_Core_DAO
::storeValues($note, $this->values
[$note->id
]);
112 $this->values
[$note->id
]['action'] = CRM_Core_Action
::formLink($links,
116 'cid' => $this->_contactId
,
124 if (!empty($note->contact_id
)) {
125 $contact = new CRM_Contact_DAO_Contact();
126 $contact->id
= $note->contact_id
;
129 $this->values
[$note->id
]['createdBy'] = $contact->display_name
;
131 $this->values
[$note->id
]['comment_count'] = CRM_Core_BAO_Note
::getChildCount($note->id
);
133 // paper icon view for attachments part
134 $paperIconAttachmentInfo = CRM_Core_BAO_File
::paperIconAttachment('civicrm_note', $note->id
);
135 $this->values
[$note->id
]['attachment'] = $paperIconAttachmentInfo;
138 $this->assign('notes', $this->values
);
140 $commentLinks = self
::commentLinks();
142 $action = array_sum(array_keys($commentLinks)) & $mask;
144 $commentAction = CRM_Core_Action
::formLink($commentLinks,
148 'pid' => $note->entity_id
,
149 'cid' => $note->entity_id
,
153 'note.comment.action',
157 $this->assign('commentAction', $commentAction);
159 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('note', $this->_contactId
);
163 * called when action is update or new.
165 public function edit() {
166 $controller = new CRM_Core_Controller_Simple('CRM_Note_Form_Note', ts('Contact Notes'), $this->_action
);
167 $controller->setEmbedded(TRUE);
169 // set the userContext stack
170 $session = CRM_Core_Session
::singleton();
171 $url = CRM_Utils_System
::url('civicrm/contact/view',
172 'action=browse&selectedChild=note&cid=' . $this->_contactId
174 $session->pushUserContext($url);
176 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean')) {
177 CRM_Core_BAO_Note
::del($this->_id
);
178 CRM_Utils_System
::redirect($url);
181 $controller->reset();
182 $controller->set('entityTable', 'civicrm_contact');
183 $controller->set('entityId', $this->_contactId
);
184 $controller->set('id', $this->_id
);
186 $controller->process();
190 public function preProcess() {
191 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
193 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
194 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
197 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
198 $this->assign('contactId', $this->_contactId
);
200 // check logged in url permission
201 CRM_Contact_Page_View
::checkUserPermission($this);
203 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
204 CRM_Utils_System
::setTitle(ts('Notes for') . ' ' . $displayName);
206 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
207 $this->assign('action', $this->_action
);
211 * the main function that is called when the page loads,
212 * it decides the which action has to be taken for the page.
216 public function run() {
219 if ($this->_action
& CRM_Core_Action
::VIEW
) {
222 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
224 $this->_permission
!= CRM_Core_Permission
::EDIT
&&
225 !CRM_Core_Permission
::check('add contact notes')
227 CRM_Core_Error
::statusBounce(ts('You do not have access to add notes.'));
232 elseif ($this->_action
& CRM_Core_Action
::UPDATE
) {
233 if ($this->_permission
!= CRM_Core_Permission
::EDIT
) {
234 CRM_Core_Error
::statusBounce(ts('You do not have access to edit this note.'));
239 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
240 if ($this->_permission
!= CRM_Core_Permission
::EDIT
) {
241 CRM_Core_Error
::statusBounce(ts('You do not have access to delete this note.'));
243 // we use the edit screen the confirm the delete
248 return parent
::run();
252 * Delete the note object from the db.
254 public function delete() {
255 CRM_Core_BAO_Note
::del($this->_id
);
262 * (reference) of action links
264 public static function &links() {
265 if (!(self
::$_links)) {
266 $deleteExtra = ts('Are you sure you want to delete this note?');
269 CRM_Core_Action
::VIEW
=> [
270 'name' => ts('View'),
271 'url' => 'civicrm/contact/view/note',
272 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
273 'title' => ts('View Note'),
275 CRM_Core_Action
::UPDATE
=> [
276 'name' => ts('Edit'),
277 'url' => 'civicrm/contact/view/note',
278 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
279 'title' => ts('Edit Note'),
281 CRM_Core_Action
::ADD
=> [
282 'name' => ts('Comment'),
283 'url' => 'civicrm/contact/view/note',
284 'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
285 'title' => ts('Add Comment'),
287 CRM_Core_Action
::DELETE
=> [
288 'name' => ts('Delete'),
289 'url' => 'civicrm/contact/view/note',
290 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
291 'title' => ts('Delete Note'),
295 return self
::$_links;
299 * Get action links for comments.
302 * (reference) of action links
304 public static function &commentLinks() {
305 if (!(self
::$_commentLinks)) {
306 self
::$_commentLinks = [
307 CRM_Core_Action
::VIEW
=> [
308 'name' => ts('View'),
309 'url' => 'civicrm/contact/view/note',
310 'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
311 'title' => ts('View Comment'),
313 CRM_Core_Action
::UPDATE
=> [
314 'name' => ts('Edit'),
315 'url' => 'civicrm/contact/view/note',
316 'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
317 'title' => ts('Edit Comment'),
319 CRM_Core_Action
::DELETE
=> [
320 'name' => ts('Delete'),
321 'url' => 'civicrm/contact/view/note',
322 'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
323 'title' => ts('Delete Comment'),
327 return self
::$_commentLinks;