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.
85 public function browse() {
86 $note = new CRM_Core_DAO_Note();
87 $note->entity_table
= 'civicrm_contact';
88 $note->entity_id
= $this->_contactId
;
90 $note->orderBy('modified_date desc');
92 //CRM-4418, handling edit and delete separately.
93 $permissions = array($this->_permission
);
94 if ($this->_permission
== CRM_Core_Permission
::EDIT
) {
95 //previously delete was subset of edit
96 //so for consistency lets grant delete also.
97 $permissions[] = CRM_Core_Permission
::DELETE
;
99 $mask = CRM_Core_Action
::mask($permissions);
102 $links = self
::links();
103 $action = array_sum(array_keys($links)) & $mask;
106 while ($note->fetch()) {
107 if (!CRM_Core_BAO_Note
::getNotePrivacyHidden($note)) {
108 CRM_Core_DAO
::storeValues($note, $values[$note->id
]);
110 $values[$note->id
]['action'] = CRM_Core_Action
::formLink($links,
114 'cid' => $this->_contactId
,
122 $contact = new CRM_Contact_DAO_Contact();
123 $contact->id
= $note->contact_id
;
126 $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_DAO
::$_nullObject
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
::UPDATE | CRM_Core_Action
::ADD
)) {
225 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
226 // we use the edit screen the confirm the delete
231 return parent
::run();
235 * Delete the note object from the db.
239 public function delete() {
240 CRM_Core_BAO_Note
::del($this->_id
);
247 * (reference) of action links
249 public static function &links() {
250 if (!(self
::$_links)) {
251 $deleteExtra = ts('Are you sure you want to delete this note?');
253 self
::$_links = array(
254 CRM_Core_Action
::VIEW
=> array(
255 'name' => ts('View'),
256 'url' => 'civicrm/contact/view/note',
257 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
258 'title' => ts('View Note'),
260 CRM_Core_Action
::UPDATE
=> array(
261 'name' => ts('Edit'),
262 'url' => 'civicrm/contact/view/note',
263 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
264 'title' => ts('Edit Note'),
266 CRM_Core_Action
::ADD
=> array(
267 'name' => ts('Comment'),
268 'url' => 'civicrm/contact/view/note',
269 'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
270 'title' => ts('Add Comment'),
272 CRM_Core_Action
::DELETE
=> array(
273 'name' => ts('Delete'),
274 'url' => 'civicrm/contact/view/note',
275 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
276 'title' => ts('Delete Note'),
280 return self
::$_links;
284 * Get action links for comments.
287 * (reference) of action links
289 public static function &commentLinks() {
290 if (!(self
::$_commentLinks)) {
291 self
::$_commentLinks = array(
292 CRM_Core_Action
::VIEW
=> array(
293 'name' => ts('View'),
294 'url' => 'civicrm/contact/view/note',
295 'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
296 'title' => ts('View Comment'),
298 CRM_Core_Action
::UPDATE
=> array(
299 'name' => ts('Edit'),
300 'url' => 'civicrm/contact/view/note',
301 'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
302 'title' => ts('Edit Comment'),
304 CRM_Core_Action
::DELETE
=> array(
305 'name' => ts('Delete'),
306 'url' => 'civicrm/contact/view/note',
307 'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
308 'title' => ts('Delete Comment'),
312 return self
::$_commentLinks;