3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * Main page for viewing Notes.
40 class CRM_Contact_Page_View_Note
extends CRM_Core_Page
{
43 * The action links for notes that we need to display for the browse screen
47 static $_links = NULL;
50 * The action links for comments that we need to display for the browse screen
54 static $_commentLinks = NULL;
57 * View details of a note
61 public function view() {
62 $note = new CRM_Core_DAO_Note();
63 $note->id
= $this->_id
;
64 if ($note->find(TRUE)) {
66 CRM_Core_DAO
::storeValues($note, $values);
67 $values['privacy'] = CRM_Core_OptionGroup
::optionLabel('note_privacy', $values['privacy']);
68 $this->assign('note', $values);
71 $comments = CRM_Core_BAO_Note
::getNoteTree($values['id'], 1);
72 if (!empty($comments)) {
73 $this->assign('comments', $comments);
76 // add attachments part
77 $currentAttachmentInfo = CRM_Core_BAO_File
::getEntityFile('civicrm_note', $this->_id
);
78 $this->assign('currentAttachmentInfo', $currentAttachmentInfo);
83 * called when action is browse
87 public function browse() {
88 $note = new CRM_Core_DAO_Note();
89 $note->entity_table
= 'civicrm_contact';
90 $note->entity_id
= $this->_contactId
;
92 $note->orderBy('modified_date desc');
94 //CRM-4418, handling edit and delete separately.
95 $permissions = array($this->_permission
);
96 if ($this->_permission
== CRM_Core_Permission
::EDIT
) {
97 //previously delete was subset of edit
98 //so for consistency lets grant delete also.
99 $permissions[] = CRM_Core_Permission
::DELETE
;
101 $mask = CRM_Core_Action
::mask($permissions);
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, $values[$note->id
]);
112 $values[$note->id
]['action'] = CRM_Core_Action
::formLink($links,
116 'cid' => $this->_contactId
,
124 $contact = new CRM_Contact_DAO_Contact();
125 $contact->id
= $note->contact_id
;
128 $values[$note->id
]['createdBy'] = $contact->display_name
;
129 $values[$note->id
]['comment_count'] = CRM_Core_BAO_Note
::getChildCount($note->id
);
131 // paper icon view for attachments part
132 $paperIconAttachmentInfo = CRM_Core_BAO_File
::paperIconAttachment('civicrm_note', $note->id
);
133 $values[$note->id
]['attachment'] = $paperIconAttachmentInfo;
137 $this->assign('notes', $values);
139 $commentLinks = self
::commentLinks();
141 $action = array_sum(array_keys($commentLinks)) & $mask;
143 $commentAction = CRM_Core_Action
::formLink($commentLinks,
147 'pid' => $note->entity_id
,
148 'cid' => $note->entity_id
,
152 'note.comment.action',
156 $this->assign('commentAction', $commentAction);
158 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('note', $this->_contactId
);
162 * called when action is update or new
166 public function edit() {
167 $controller = new CRM_Core_Controller_Simple('CRM_Note_Form_Note', ts('Contact Notes'), $this->_action
);
168 $controller->setEmbedded(TRUE);
170 // set the userContext stack
171 $session = CRM_Core_Session
::singleton();
172 $url = CRM_Utils_System
::url('civicrm/contact/view',
173 'action=browse&selectedChild=note&cid=' . $this->_contactId
175 $session->pushUserContext($url);
177 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean',
178 CRM_Core_DAO
::$_nullObject
181 CRM_Core_BAO_Note
::del($this->_id
);
182 CRM_Utils_System
::redirect($url);
185 $controller->reset();
186 $controller->set('entityTable', 'civicrm_contact');
187 $controller->set('entityId', $this->_contactId
);
188 $controller->set('id', $this->_id
);
190 $controller->process();
194 public function preProcess() {
195 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
197 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
198 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
201 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
202 $this->assign('contactId', $this->_contactId
);
204 // check logged in url permission
205 CRM_Contact_Page_View
::checkUserPermission($this);
207 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
208 CRM_Utils_System
::setTitle(ts('Notes for') . ' ' . $displayName);
210 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
211 $this->assign('action', $this->_action
);
215 * the main function that is called when the page loads,
216 * it decides the which action has to be taken for the page.
220 public function run() {
223 if ($this->_action
& CRM_Core_Action
::VIEW
) {
226 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
229 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
230 // we use the edit screen the confirm the delete
235 return parent
::run();
239 * Delete the note object from the db
243 public function delete() {
244 CRM_Core_BAO_Note
::del($this->_id
);
251 * (reference) of action links
253 public static function &links() {
254 if (!(self
::$_links)) {
255 $deleteExtra = ts('Are you sure you want to delete this note?');
257 self
::$_links = array(
258 CRM_Core_Action
::VIEW
=> array(
259 'name' => ts('View'),
260 'url' => 'civicrm/contact/view/note',
261 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
262 'title' => ts('View Note'),
264 CRM_Core_Action
::UPDATE
=> array(
265 'name' => ts('Edit'),
266 'url' => 'civicrm/contact/view/note',
267 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
268 'title' => ts('Edit Note'),
270 CRM_Core_Action
::ADD
=> array(
271 'name' => ts('Comment'),
272 'url' => 'civicrm/contact/view/note',
273 'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
274 'title' => ts('Add Comment'),
276 CRM_Core_Action
::DELETE
=> array(
277 'name' => ts('Delete'),
278 'url' => 'civicrm/contact/view/note',
279 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
280 'title' => ts('Delete Note'),
284 return self
::$_links;
288 * Get action links for comments
291 * (reference) of action links
293 public static function &commentLinks() {
294 if (!(self
::$_commentLinks)) {
295 self
::$_commentLinks = array(
296 CRM_Core_Action
::VIEW
=> array(
297 'name' => ts('View'),
298 'url' => 'civicrm/contact/view/note',
299 'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
300 'title' => ts('View Comment'),
302 CRM_Core_Action
::UPDATE
=> array(
303 'name' => ts('Edit'),
304 'url' => 'civicrm/contact/view/note',
305 'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
306 'title' => ts('Edit Comment'),
308 CRM_Core_Action
::DELETE
=> array(
309 'name' => ts('Delete'),
310 'url' => 'civicrm/contact/view/note',
311 'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
312 'title' => ts('Delete Comment'),
316 return self
::$_commentLinks;