$followupParams['activity_type_id'] = $params['followup_activity_type_id'];
// Get Subject of Follow-up Activiity, CRM-4491
$followupParams['subject'] = CRM_Utils_Array::value('followup_activity_subject', $params);
+ $followupParams['assignee_contact_id'] = CRM_Utils_Array::value('followup_assignee_contact_id', $params);
//create target contact for followup
if (CRM_Utils_Array::value('target_contact_id', $params)) {
/**
* Retrieve assignee names by activity_id
*
- * @param int $id ID of the activity
+ * @param array $activityIDs IDs of the activities
* @param boolean $isDisplayName if set returns display names of assignees
* @param boolean $skipDetails if false returns all details of assignee contact.
*
* @access public
*
*/
- static function getAssigneeNames($activityID, $isDisplayName = FALSE, $skipDetails = TRUE) {
+ static function getAssigneeNames($activityIDs, $isDisplayName = FALSE, $skipDetails = TRUE) {
$assigneeNames = array();
- if (empty($activityID)) {
+ if (empty($activityIDs)) {
return $assigneeNames;
}
$activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
if (!$skipDetails) {
$whereClause = " AND ce.is_primary= 1";
}
+ $inClause = implode(",", $activityIDs);
$query = "
-SELECT contact_a.id, contact_a.sort_name, contact_a.display_name, ce.email
+SELECT contact_a.id, contact_a.sort_name, contact_a.display_name, ce.email,
+ civicrm_activity_contact.activity_id
FROM civicrm_contact contact_a
INNER JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = contact_a.id
LEFT JOIN civicrm_email ce ON ce.contact_id = contact_a.id
-WHERE civicrm_activity_contact.activity_id = %1
+WHERE civicrm_activity_contact.activity_id IN ( $inClause )
AND contact_a.is_deleted = 0
AND civicrm_activity_contact.record_type_id = $assigneeID
{$whereClause}
";
- $queryParam = array(1 => array($activityID, 'Integer'));
- $dao = CRM_Core_DAO::executeQuery($query, $queryParam);
+ $dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
if (!$isDisplayName) {
$assigneeNames[$dao->id] = $dao->sort_name;
$assigneeNames[$dao->id]['sort_name'] = $dao->sort_name;
$assigneeNames[$dao->id]['email'] = $dao->email;
$assigneeNames[$dao->id]['role'] = ts('Activity Assignee');
+ $assigneeNames[$dao->id]['activity_id'] = $dao->activity_id;
}
}
}
// Set title
if (isset($activityTName)) {
$activityName = CRM_Utils_Array::value($this->_activityTypeId, $activityTName);
- $this->assign('pageTitle', ts('%1 Activity', $activityName));
+ $this->assign('pageTitle', ts('%1 Activity', array( 1 => $activityName)));
if ($this->_currentlyViewedContactId) {
$displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId);
$admin
);
+ $followupAssigneeContactField =& $this->add( 'text', 'followup_assignee_contact_id', ts('assignee') );
+
$this->add('hidden', 'source_contact_qid', '', array('id' => 'source_contact_qid'));
CRM_Contact_Form_NewContact::buildQuickForm($this);
$this->add('text', 'assignee_contact_id', ts('assignee'));
+ $this->add( 'text', 'followup_assignee_contact_id', ts('assignee'));
if ($sourceContactField->getValue()) {
$this->assign('source_contact', $sourceContactField->getValue());
else {
$params['assignee_contact_id'] = array();
}
+ // civicrm-10043 - 14/12/13
+ if ( CRM_Utils_Array::value( 'followup_assignee_contact_id', $params ) ) {
+ $params['followup_assignee_contact_id'] = explode( ',', $params['followup_assignee_contact_id'] );
+ }
+ else {
+ $params['followup_assignee_contact_id'] = array( );
+ }
// get ids for associated contacts
if (!$params['source_contact_id']) {
// create follow up activity if needed
$followupStatus = '';
+ $followupActivity = NULL;
if (CRM_Utils_Array::value('followup_activity_type_id', $params)) {
- CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
+ $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
$followupStatus = ts('A followup activity has been scheduled.');
}
// send copy to assignee contacts.CRM-4509
$mailStatus = '';
- if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) &&
- CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
- 'activity_assignee_notification'
- )
- ) {
- $mailToContacts = array();
- $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE);
+ if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
+ 'activity_assignee_notification')) {
+ $activityIDs = array($activity->id);
+ if ($followupActivity) {
+ $activityIDs = array_merge($activityIDs, array($followupActivity->id));
+ }
+ $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityIDs, TRUE, FALSE);
- //build an associative array with unique email addresses.
- foreach ($activityAssigned as $id => $dnc) {
- if (isset($id) && array_key_exists($id, $assigneeContacts)) {
- $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id];
+ if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
+ $mailToContacts = array();
+
+ //build an associative array with unique email addresses.
+ foreach ($activityAssigned as $id => $dnc) {
+ if (isset($id) && array_key_exists($id, $assigneeContacts)) {
+ $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id];
+ }
}
- }
- if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) {
- //include attachments while sending a copy of activity.
- $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
+ if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) {
+ //include attachments while sending a copy of activity.
+ $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
+
+ $ics = new CRM_Activity_BAO_ICalendar($activity);
+ $ics->addAttachment($attachments, $mailToContacts);
- $ics = new CRM_Activity_BAO_ICalendar($activity);
- $ics->addAttachment($attachments, $mailToContacts);
+ // CRM-8400 add param with _currentlyViewedContactId for URL link in mail
+ CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL);
- // CRM-8400 add param with _currentlyViewedContactId for URL link in mail
- CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL);
+ $ics->cleanup();
- $ics->cleanup();
+ $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s).");
+ }
+ }
+
+ // Also send email to follow-up activity assignees if set
+ if ($followupActivity) {
+ $mailToFollowupContacts = array();
+ foreach ($assigneeContacts as $values) {
+ if ($values['activity_id'] == $followupActivity->id) {
+ $mailToFollowupContacts[$values['email']] = $values;
+ }
+ }
+
+ if (!CRM_Utils_array::crmIsEmptyArray($mailToFollowupContacts)) {
+ $ics = new CRM_Activity_BAO_ICalendar($followupActivity);
+ $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $followupActivity->id);
+ $ics->addAttachment($attachments, $mailToFollowupContacts);
- $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s).");
+ CRM_Case_BAO_Case::sendActivityCopy(NULL, $followupActivity->id, $mailToFollowupContacts, $attachments, NULL);
+
+ $ics->cleanup();
+
+ $mailStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s).");
+ }
}
}
$mailStatus = ts("A copy of the activity has also been sent to selected contacts(s).");
}
else {
- $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE);
+ $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activity->id), TRUE, FALSE);
$mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s).");
}
if (!empty($activityDAO->assigneeID)) {
//allow multiple assignee contacts.CRM-4503.
- $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityDAO->id, TRUE);
+ $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activityDAO->id), TRUE);
foreach ($assignee_contact_names as & $assignee) {
// add Assignee to the strings to be redacted across the case session
<td class="label">{$form.followup_activity_subject.label}</td>
<td>{$form.followup_activity_subject.html|crmAddClass:huge}</td>
</tr>
+ <tr>
+ <td class="label">{ts}Assign To{/ts}</td>
+ <td>{$form.followup_assignee_contact_id.html}
+ {edit}<span class="description">{ts}You can optionally assign this activity to someone. Assigned activities will appear in their Activities listing at CiviCRM Home.{/ts}
+ </span>
+ {/edit}
+ </td>
+ </tr>
</table>
</div><!-- /.crm-accordion-body -->
</div><!-- /.crm-accordion-wrapper -->
{* added onload javascript for source contact*}
{literal}
<script type="text/javascript">
- var assignee_contact = '';
+ var assignee_contact = followup_assignee_contact = '';
{/literal}
{if $assignee_contact}
var assignee_contact = {$assignee_contact};
{/if}
+ {if $followup_assignee_contact}
+ var followup_assignee_contact = {$followup_assignee_contact};
+ {/if}
{literal}
- var assignee_contact_id = null;
+ var assignee_contact_id = followup_assignee_contact_id = null;
//loop to set the value of cc and bcc if form rule.
var toDataUrl = "{/literal}{crmURL p='civicrm/ajax/checkemail' q='id=1&noemail=1' h=0 }{literal}"; {/literal}
- {foreach from=","|explode:"assignee" key=key item=element}
+ {foreach from=","|explode:"assignee,followup_assignee" key=key item=element}
{assign var=currentElement value=`$element`_contact_id}
{if $form.$currentElement.value}
{literal} var {/literal}{$currentElement}{literal} = cj.ajax({ url: toDataUrl + "&cid={/literal}{$form.$currentElement.value}{literal}", async: false }).responseText;{/literal}
if ( assignee_contact_id ) {
eval( 'assignee_contact = ' + assignee_contact_id );
}
+ if ( followup_assignee_contact_id ) {
+ eval( 'followup_assignee_contact = ' + followup_assignee_contact_id );
+ }
cj(function( ) {
{/literal}
var hintText = "{/literal}{ts escape='js'}Start typing a name or email address.{/ts}{literal}";
cj( "#assignee_contact_id").tokenInput( tokenDataUrl_assignee, { prePopulate: assignee_contact, theme: 'facebook', hintText: hintText });
+ cj( "#followup_assignee_contact_id").tokenInput( tokenDataUrl_assignee, { prePopulate: followup_assignee_contact, theme: 'facebook', hintText: hintText });
cj( 'ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px' );
cj('#source_contact_id').autocomplete( sourceDataUrl, { width : 180, selectFirst : false, hintText: hintText, matchContains: true, minChars: 1, max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal}
}).result( function(event, data, formatted) { cj( "#source_contact_qid" ).val( data[1] );