3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
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 = array($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 $contact = new CRM_Contact_DAO_Contact();
121 $contact->id
= $note->contact_id
;
124 $values[$note->id
]['createdBy'] = $contact->display_name
;
125 $values[$note->id
]['comment_count'] = CRM_Core_BAO_Note
::getChildCount($note->id
);
127 // paper icon view for attachments part
128 $paperIconAttachmentInfo = CRM_Core_BAO_File
::paperIconAttachment('civicrm_note', $note->id
);
129 $values[$note->id
]['attachment'] = $paperIconAttachmentInfo;
133 $this->assign('notes', $values);
135 $commentLinks = self
::commentLinks();
137 $action = array_sum(array_keys($commentLinks)) & $mask;
139 $commentAction = CRM_Core_Action
::formLink($commentLinks,
143 'pid' => $note->entity_id
,
144 'cid' => $note->entity_id
,
148 'note.comment.action',
152 $this->assign('commentAction', $commentAction);
154 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('note', $this->_contactId
);
158 * called when action is update or new.
160 public function edit() {
161 $controller = new CRM_Core_Controller_Simple('CRM_Note_Form_Note', ts('Contact Notes'), $this->_action
);
162 $controller->setEmbedded(TRUE);
164 // set the userContext stack
165 $session = CRM_Core_Session
::singleton();
166 $url = CRM_Utils_System
::url('civicrm/contact/view',
167 'action=browse&selectedChild=note&cid=' . $this->_contactId
169 $session->pushUserContext($url);
171 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean')) {
172 CRM_Core_BAO_Note
::del($this->_id
);
173 CRM_Utils_System
::redirect($url);
176 $controller->reset();
177 $controller->set('entityTable', 'civicrm_contact');
178 $controller->set('entityId', $this->_contactId
);
179 $controller->set('id', $this->_id
);
181 $controller->process();
185 public function preProcess() {
186 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
188 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
189 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
192 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
193 $this->assign('contactId', $this->_contactId
);
195 // check logged in url permission
196 CRM_Contact_Page_View
::checkUserPermission($this);
198 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
199 CRM_Utils_System
::setTitle(ts('Notes for') . ' ' . $displayName);
201 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
202 $this->assign('action', $this->_action
);
206 * the main function that is called when the page loads,
207 * it decides the which action has to be taken for the page.
211 public function run() {
214 if ($this->_action
& CRM_Core_Action
::VIEW
) {
217 elseif ($this->_action
& CRM_Core_Action
::ADD
) {
219 $this->_permission
!= CRM_Core_Permission
::EDIT
&&
220 !CRM_Core_Permission
::check('add contact notes')
222 CRM_Core_Error
::statusBounce(ts('You do not have access to add notes.'));
227 elseif ($this->_action
& CRM_Core_Action
::UPDATE
) {
228 if ($this->_permission
!= CRM_Core_Permission
::EDIT
) {
229 CRM_Core_Error
::statusBounce(ts('You do not have access to edit this note.'));
234 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
235 if ($this->_permission
!= CRM_Core_Permission
::EDIT
) {
236 CRM_Core_Error
::statusBounce(ts('You do not have access to delete this note.'));
238 // we use the edit screen the confirm the delete
243 return parent
::run();
247 * Delete the note object from the db.
249 public function delete() {
250 CRM_Core_BAO_Note
::del($this->_id
);
257 * (reference) of action links
259 public static function &links() {
260 if (!(self
::$_links)) {
261 $deleteExtra = ts('Are you sure you want to delete this note?');
263 self
::$_links = array(
264 CRM_Core_Action
::VIEW
=> array(
265 'name' => ts('View'),
266 'url' => 'civicrm/contact/view/note',
267 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
268 'title' => ts('View Note'),
270 CRM_Core_Action
::UPDATE
=> array(
271 'name' => ts('Edit'),
272 'url' => 'civicrm/contact/view/note',
273 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
274 'title' => ts('Edit Note'),
276 CRM_Core_Action
::ADD
=> array(
277 'name' => ts('Comment'),
278 'url' => 'civicrm/contact/view/note',
279 'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
280 'title' => ts('Add Comment'),
282 CRM_Core_Action
::DELETE
=> array(
283 'name' => ts('Delete'),
284 'url' => 'civicrm/contact/view/note',
285 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
286 'title' => ts('Delete Note'),
290 return self
::$_links;
294 * Get action links for comments.
297 * (reference) of action links
299 public static function &commentLinks() {
300 if (!(self
::$_commentLinks)) {
301 self
::$_commentLinks = array(
302 CRM_Core_Action
::VIEW
=> array(
303 'name' => ts('View'),
304 'url' => 'civicrm/contact/view/note',
305 'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
306 'title' => ts('View Comment'),
308 CRM_Core_Action
::UPDATE
=> array(
309 'name' => ts('Edit'),
310 'url' => 'civicrm/contact/view/note',
311 'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
312 'title' => ts('Edit Comment'),
314 CRM_Core_Action
::DELETE
=> array(
315 'name' => ts('Delete'),
316 'url' => 'civicrm/contact/view/note',
317 'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
318 'title' => ts('Delete Comment'),
322 return self
::$_commentLinks;