3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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
48 static $_links = NULL;
51 * The action links for comments that we need to display for the browse screen
56 static $_commentLinks = NULL;
59 * View details of a note
65 $note = new CRM_Core_DAO_Note();
66 $note->id
= $this->_id
;
67 if ($note->find(TRUE)) {
69 CRM_Core_DAO
::storeValues($note, $values);
70 $values['privacy'] = CRM_Core_OptionGroup
::optionLabel('note_privacy', $values['privacy']);
71 $this->assign('note', $values);
74 $comments = CRM_Core_BAO_Note
::getNoteTree($values['id'], 1);
75 if (!empty($comments)) {
76 $this->assign('comments', $comments);
79 // add attachments part
80 $currentAttachmentInfo = CRM_Core_BAO_File
::getEntityFile('civicrm_note', $this->_id
);
81 $this->assign('currentAttachmentInfo', $currentAttachmentInfo);
86 * This function is called when action is browse
92 $note = new CRM_Core_DAO_Note();
93 $note->entity_table
= 'civicrm_contact';
94 $note->entity_id
= $this->_contactId
;
96 $note->orderBy('modified_date desc');
98 //CRM-4418, handling edit and delete separately.
99 $permissions = array($this->_permission
);
100 if ($this->_permission
== CRM_Core_Permission
::EDIT
) {
101 //previously delete was subset of edit
102 //so for consistency lets grant delete also.
103 $permissions[] = CRM_Core_Permission
::DELETE
;
105 $mask = CRM_Core_Action
::mask($permissions);
108 $links = self
::links();
109 $action = array_sum(array_keys($links)) & $mask;
112 while ($note->fetch()) {
113 if (!CRM_Core_BAO_Note
::getNotePrivacyHidden($note)) {
114 CRM_Core_DAO
::storeValues($note, $values[$note->id
]);
116 $values[$note->id
]['action'] = CRM_Core_Action
::formLink($links,
120 'cid' => $this->_contactId
,
128 $contact = new CRM_Contact_DAO_Contact();
129 $contact->id
= $note->contact_id
;
132 $values[$note->id
]['createdBy'] = $contact->display_name
;
133 $values[$note->id
]['comment_count'] = CRM_Core_BAO_Note
::getChildCount($note->id
);
135 // paper icon view for attachments part
136 $paperIconAttachmentInfo = CRM_Core_BAO_File
::paperIconAttachment('civicrm_note', $note->id
);
137 $values[$note->id
]['attachment'] = $paperIconAttachmentInfo;
141 $this->assign('notes', $values);
143 $commentLinks = self
::commentLinks();
145 $action = array_sum(array_keys($commentLinks)) & $mask;
147 $commentAction = CRM_Core_Action
::formLink($commentLinks,
151 'pid' => $note->entity_id
,
152 'cid' => $note->entity_id
,
156 'note.comment.action',
160 $this->assign('commentAction', $commentAction);
162 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('note', $this->_contactId
);
166 * This function is called when action is update or new
172 $controller = new CRM_Core_Controller_Simple('CRM_Note_Form_Note', ts('Contact Notes'), $this->_action
);
173 $controller->setEmbedded(TRUE);
175 // set the userContext stack
176 $session = CRM_Core_Session
::singleton();
177 $url = CRM_Utils_System
::url('civicrm/contact/view',
178 'action=browse&selectedChild=note&cid=' . $this->_contactId
180 $session->pushUserContext($url);
182 if (CRM_Utils_Request
::retrieve('confirmed', 'Boolean',
183 CRM_Core_DAO
::$_nullObject
185 CRM_Core_BAO_Note
::del($this->_id
);
186 CRM_Utils_System
::redirect($url);
189 $controller->reset();
190 $controller->set('entityTable', 'civicrm_contact');
191 $controller->set('entityId', $this->_contactId
);
192 $controller->set('id', $this->_id
);
194 $controller->process();
198 function preProcess() {
199 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
201 if ($this->_id
&& CRM_Core_BAO_Note
::getNotePrivacyHidden($this->_id
)) {
202 CRM_Core_Error
::statusBounce(ts('You do not have access to this note.'));
205 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
206 $this->assign('contactId', $this->_contactId
);
208 // check logged in url permission
209 CRM_Contact_Page_View
::checkUserPermission($this);
212 CRM_Contact_Page_View
::setTitle($this->_contactId
);
214 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
215 CRM_Utils_System
::setTitle(ts('Notes for') . ' ' . $displayName);
217 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
218 $this->assign('action', $this->_action
);
222 * This function is the main function that is called when the page loads,
223 * it decides the which action has to be taken for the page.
231 if ($this->_action
& CRM_Core_Action
::VIEW
) {
234 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
237 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
238 // we use the edit screen the confirm the delete
243 return parent
::run();
247 * delete the note object from the db
253 CRM_Core_BAO_Note
::del($this->_id
);
259 * @return array (reference) of action links
262 static function &links() {
263 if (!(self
::$_links)) {
264 $deleteExtra = ts('Are you sure you want to delete this note?');
266 self
::$_links = array(
267 CRM_Core_Action
::VIEW
=> array(
268 'name' => ts('View'),
269 'url' => 'civicrm/contact/view/note',
270 'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
271 'title' => ts('View Note'),
273 CRM_Core_Action
::UPDATE
=> array(
274 'name' => ts('Edit'),
275 'url' => 'civicrm/contact/view/note',
276 'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
277 'title' => ts('Edit Note'),
279 CRM_Core_Action
::ADD
=> array(
280 'name' => ts('Comment'),
281 'url' => 'civicrm/contact/view/note',
282 'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
283 'title' => ts('Add Comment'),
285 CRM_Core_Action
::DELETE
=> array(
286 'name' => ts('Delete'),
287 'url' => 'civicrm/contact/view/note',
288 'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
289 'title' => ts('Delete Note'),
293 return self
::$_links;
297 * Get action links for comments
299 * @return array (reference) of action links
302 static function &commentLinks() {
303 if (!(self
::$_commentLinks)) {
304 self
::$_commentLinks = array(
305 CRM_Core_Action
::VIEW
=> array(
306 'name' => ts('View'),
307 'url' => 'civicrm/contact/view/note',
308 'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
309 'title' => ts('View Comment'),
311 CRM_Core_Action
::UPDATE
=> array(
312 'name' => ts('Edit'),
313 'url' => 'civicrm/contact/view/note',
314 'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
315 'title' => ts('Edit Comment'),
317 CRM_Core_Action
::DELETE
=> array(
318 'name' => ts('Delete'),
319 'url' => 'civicrm/contact/view/note',
320 'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
321 'title' => ts('Delete Comment'),
325 return self
::$_commentLinks;