3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
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 static $_links = NULL;
47 * The action links for comments that we need to display for the browse screen
51 static $_commentLinks = NULL;
54 * View details of a note.
56 public function view() {
57 $note = new CRM_Core_DAO_Note();
58 $note->id
= $this->_id
;
59 if ($note->find(TRUE)) {
62 CRM_Core_DAO
::storeValues($note, $values);
63 $values['privacy'] = CRM_Core_PseudoConstant
::getLabel('CRM_Core_BAO_Note', 'privacy', $values['privacy']);
64 $this->assign('note', $values);
67 $comments = CRM_Core_BAO_Note
::getNoteTree($values['id'], 1);
68 if (!empty($comments)) {
69 $this->assign('comments', $comments);
72 // add attachments part
73 $currentAttachmentInfo = CRM_Core_BAO_File
::getEntityFile('civicrm_note', $this->_id
);
74 $this->assign('currentAttachmentInfo', $currentAttachmentInfo);
79 * called when action is browse.
81 public function browse() {
82 $note = new CRM_Core_DAO_Note();
83 $note->entity_table
= 'civicrm_contact';
84 $note->entity_id
= $this->_contactId
;
86 $note->orderBy('modified_date desc');
88 //CRM-4418, handling edit and delete separately.
89 $permissions = [$this->_permission
];
90 if ($this->_permission
== CRM_Core_Permission
::EDIT
) {
91 //previously delete was subset of edit
92 //so for consistency lets grant delete also.
93 $permissions[] = CRM_Core_Permission
::DELETE
;
95 $mask = CRM_Core_Action
::mask($permissions);
97 $this->assign('canAddNotes', CRM_Core_Permission
::check('add contact notes'));
100 $links = self
::links();
101 $action = array_sum(array_keys($links)) & $mask;
104 while ($note->fetch()) {
105 if (!CRM_Core_BAO_Note
::getNotePrivacyHidden($note)) {
106 CRM_Core_DAO
::storeValues($note, $values[$note->id
]);
108 $values[$note->id
]['action'] = CRM_Core_Action
::formLink($links,
112 'cid' => $this->_contactId
,
120 if (!empty($note->contact_id
)) {
121 $contact = new CRM_Contact_DAO_Contact();
122 $contact->id
= $note->contact_id
;
125 $values[$note->id
]['createdBy'] = $contact->display_name
;
127 $values[$note->id
]['comment_count'] = CRM_Core_BAO_Note
::getChildCount($note->id
);
129 // paper icon view for attachments part
130 $paperIconAttachmentInfo = CRM_Core_BAO_File
::paperIconAttachment('civicrm_note', $note->id
);
131 $values[$note->id
]['attachment'] = $paperIconAttachmentInfo;
135 $this->assign('notes', $values);
137 $commentLinks = self
::commentLinks();
139 $action = array_sum(array_keys($commentLinks)) & $mask;
141 $commentAction = CRM_Core_Action
::formLink($commentLinks,
145 'pid' => $note->entity_id
,
146 'cid' => $note->entity_id
,
150 'note.comment.action',
154 $this->assign('commentAction', $commentAction);
156 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('note', $this->_contactId
);
160 * called when action is update or new.
162 public function edit() {
163 $controller = new CRM_Core_Controller_Simple('CRM_Note_Form_Note', ts('Contact Notes'), $this->_action
);
164 $controller->setEmbedded(TRUE);
166 // set the userContext stack
167 $session = CRM_Core_Session
::singleton();
168 $url = CRM_Utils_System
::url('civicrm/contact/view',
169 'action=browse&selectedChild=note&cid=' . $this->_contactId
171 $session->pushUserContext($url);
173 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean')) {
174 CRM_Core_BAO_Note
::del($this->_id
);
175 CRM_Utils_System
::redirect($url);
178 $controller->reset();
179 $controller->set('entityTable', 'civicrm_contact');
180 $controller->set('entityId', $this->_contactId
);
181 $controller->set('id', $this->_id
);
183 $controller->process();
187 public function preProcess() {
188 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
190 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
191 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
194 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
195 $this->assign('contactId', $this->_contactId
);
197 // check logged in url permission
198 CRM_Contact_Page_View
::checkUserPermission($this);
200 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
201 CRM_Utils_System
::setTitle(ts('Notes for') . ' ' . $displayName);
203 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
204 $this->assign('action', $this->_action
);
208 * the main function that is called when the page loads,
209 * it decides the which action has to be taken for the page.
213 public function run() {
216 if ($this->_action
& CRM_Core_Action
::VIEW
) {
219 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
221 $this->_permission
!= CRM_Core_Permission
::EDIT
&&
222 !CRM_Core_Permission
::check('add contact notes')
224 CRM_Core_Error
::statusBounce(ts('You do not have access to add notes.'));
229 elseif ($this->_action
& CRM_Core_Action
::UPDATE
) {
230 if ($this->_permission
!= CRM_Core_Permission
::EDIT
) {
231 CRM_Core_Error
::statusBounce(ts('You do not have access to edit this note.'));
236 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
237 if ($this->_permission
!= CRM_Core_Permission
::EDIT
) {
238 CRM_Core_Error
::statusBounce(ts('You do not have access to delete this note.'));
240 // we use the edit screen the confirm the delete
245 return parent
::run();
249 * Delete the note object from the db.
251 public function delete() {
252 CRM_Core_BAO_Note
::del($this->_id
);
259 * (reference) of action links
261 public static function &links() {
262 if (!(self
::$_links)) {
263 $deleteExtra = ts('Are you sure you want to delete this note?');
266 CRM_Core_Action
::VIEW
=> [
267 'name' => ts('View'),
268 'url' => 'civicrm/contact/view/note',
269 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
270 'title' => ts('View Note'),
272 CRM_Core_Action
::UPDATE
=> [
273 'name' => ts('Edit'),
274 'url' => 'civicrm/contact/view/note',
275 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
276 'title' => ts('Edit Note'),
278 CRM_Core_Action
::ADD
=> [
279 'name' => ts('Comment'),
280 'url' => 'civicrm/contact/view/note',
281 'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
282 'title' => ts('Add Comment'),
284 CRM_Core_Action
::DELETE
=> [
285 'name' => ts('Delete'),
286 'url' => 'civicrm/contact/view/note',
287 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
288 'title' => ts('Delete Note'),
292 return self
::$_links;
296 * Get action links for comments.
299 * (reference) of action links
301 public static function &commentLinks() {
302 if (!(self
::$_commentLinks)) {
303 self
::$_commentLinks = [
304 CRM_Core_Action
::VIEW
=> [
305 'name' => ts('View'),
306 'url' => 'civicrm/contact/view/note',
307 'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
308 'title' => ts('View Comment'),
310 CRM_Core_Action
::UPDATE
=> [
311 'name' => ts('Edit'),
312 'url' => 'civicrm/contact/view/note',
313 'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
314 'title' => ts('Edit Comment'),
316 CRM_Core_Action
::DELETE
=> [
317 'name' => ts('Delete'),
318 'url' => 'civicrm/contact/view/note',
319 'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
320 'title' => ts('Delete Comment'),
324 return self
::$_commentLinks;