bulk comment fixes
[civicrm-core.git] / CRM / Contact / BAO / GroupContact.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35 class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact {
36
37 /**
38 * class constructor
39 */
40 function __construct() {
41 parent::__construct();
42 }
43
44 /**
45 * takes an associative array and creates a groupContact object
46 *
47 * the function extract all the params it needs to initialize the create a
48 * group object. the params array could contain additional unused name/value
49 * pairs
50 *
51 * @param array $params (reference ) an assoc array of name/value pairs
52 *
53 * @return object CRM_Contact_BAO_Group object
54 * @access public
55 * @static
56 */
57 static function add(&$params) {
58
59 $dataExists = self::dataExists($params);
60 if (!$dataExists) {
61 return NULL;
62 }
63
64 $groupContact = new CRM_Contact_BAO_GroupContact();
65 $groupContact->copyValues($params);
66 CRM_Contact_BAO_SubscriptionHistory::create($params);
67 $groupContact->save();
68 return $groupContact;
69 }
70
71 /**
72 * Check if there is data to create the object
73 *
74 * @param array $params (reference ) an assoc array of name/value pairs
75 *
76 * @return boolean
77 * @access public
78 * @static
79 */
80 static function dataExists(&$params) {
81 // return if no data present
82 if ($params['group_id'] == 0) {
83 return FALSE;
84 }
85
86 return TRUE;
87 }
88
89 /**
90 * Given the list of params in the params array, fetch the object
91 * and store the values in the values array
92 *
93 * @param array $params input parameters to find object
94 * @param array $values output values of the object
95 *
96 * @internal param array $ids the array that holds all the db ids
97 *
98 * @return array (reference) the values that could be potentially assigned to smarty
99 * @access public
100 * @static
101 */
102 static function getValues(&$params, &$values) {
103 if (empty($params)) {
104 return NULL;
105 }
106 $values['group']['data'] = &CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'],
107 'Added',
108 3
109 );
110
111 // get the total count of groups
112 $values['group']['totalCount'] = CRM_Contact_BAO_GroupContact::getContactGroup($params['contact_id'],
113 'Added',
114 NULL,
115 TRUE
116 );
117
118 return NULL;
119 }
120
121 /**
122 * Given an array of contact ids, add all the contacts to the group
123 *
124 * @param array $contactIds the array of contact ids to be added
125 * @param int $groupId the id of the group
126 * @param string $method
127 * @param string $status
128 * @param int $tracking
129 *
130 * @return array (total, added, notAdded) count of contacts added to group
131 * @access public
132 * @static
133 */
134 static function addContactsToGroup(
135 $contactIds,
136 $groupId,
137 $method = 'Admin',
138 $status = 'Added',
139 $tracking = NULL
140 ) {
141
142
143 CRM_Utils_Hook::pre('create', 'GroupContact', $groupId, $contactIds);
144
145 list($numContactsAdded,
146 $numContactsNotAdded
147 ) = self::bulkAddContactsToGroup($contactIds,
148 $groupId,
149 $method,
150 $status,
151 $tracking
152 );
153
154 // also reset the acl cache
155 $config = CRM_Core_Config::singleton();
156 if (!$config->doNotResetCache) {
157 CRM_ACL_BAO_Cache::resetCache();
158 }
159
160 // reset the group contact cache for all group(s)
161 // if this group is being used as a smart group
162 CRM_Contact_BAO_GroupContactCache::remove();
163
164 CRM_Utils_Hook::post('create', 'GroupContact', $groupId, $contactIds);
165
166 return array(count($contactIds), $numContactsAdded, $numContactsNotAdded);
167 }
168
169 /**
170 * Given an array of contact ids, remove all the contacts from the group
171 *
172 * @param array $contactIds (reference ) the array of contact ids to be removed
173 * @param int $groupId the id of the group
174 *
175 * @param string $method
176 * @param string $status
177 * @param null $tracking
178 *
179 * @return array (total, removed, notRemoved) count of contacts removed to group
180 * @access public
181 * @static
182 */
183 static function removeContactsFromGroup(
184 &$contactIds,
185 $groupId,
186 $method = 'Admin',
187 $status = 'Removed',
188 $tracking = NULL
189 ) {
190 if (!is_array($contactIds)) {
191 return array(0, 0, 0);
192 }
193
194 if ($status == 'Removed' || $status == 'Deleted') {
195 $op = 'delete';
196 }
197 else {
198 $op = 'edit';
199 }
200
201 CRM_Utils_Hook::pre($op, 'GroupContact', $groupId, $contactIds);
202
203 $date = date('YmdHis');
204 $numContactsRemoved = 0;
205 $numContactsNotRemoved = 0;
206
207 $group = new CRM_Contact_DAO_Group();
208 $group->id = $groupId;
209 $group->find(TRUE);
210
211 foreach ($contactIds as $contactId) {
212 if ($status == 'Deleted') {
213 $query = "DELETE FROM civicrm_group_contact WHERE contact_id=$contactId AND group_id=$groupId";
214 $dao = CRM_Core_DAO::executeQuery($query);
215 $historyParams = array(
216 'group_id' => $groupId,
217 'contact_id' => $contactId,
218 'status' => $status,
219 'method' => $method,
220 'date' => $date,
221 'tracking' => $tracking,
222 );
223 CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
224 }
225 else {
226 $groupContact = new CRM_Contact_DAO_GroupContact();
227 $groupContact->group_id = $groupId;
228 $groupContact->contact_id = $contactId;
229 // check if the selected contact id already a member, or if this is
230 // an opt-out of a smart group.
231 // if not a member remove to groupContact else keep the count of contacts that are not removed
232 if ($groupContact->find(TRUE) || $group->saved_search_id) {
233 // remove the contact from the group
234 $numContactsRemoved++;
235 }
236 else {
237 $numContactsNotRemoved++;
238 }
239
240 //now we grant the negative membership to contact if not member. CRM-3711
241 $historyParams = array(
242 'group_id' => $groupId,
243 'contact_id' => $contactId,
244 'status' => $status,
245 'method' => $method,
246 'date' => $date,
247 'tracking' => $tracking,
248 );
249 CRM_Contact_BAO_SubscriptionHistory::create($historyParams);
250 $groupContact->status = $status;
251 $groupContact->save();
252 }
253 }
254
255 // also reset the acl cache
256 $config = CRM_Core_Config::singleton();
257 if (!$config->doNotResetCache) {
258 CRM_ACL_BAO_Cache::resetCache();
259 }
260
261 // reset the group contact cache for all group(s)
262 // if this group is being used as a smart group
263 CRM_Contact_BAO_GroupContactCache::remove();
264
265 CRM_Utils_Hook::post($op, 'GroupContact', $groupId, $contactIds);
266
267 return array(count($contactIds), $numContactsRemoved, $numContactsNotRemoved);
268 }
269
270 /**
271 * Function to get list of all the groups and groups for a contact
272 *
273 * @param int $contactId contact id
274 *
275 * @param bool $visibility
276 *
277 * @access public
278 *
279 * @return array $values this array has key-> group id and value group title
280 * @static
281 */
282 static function getGroupList($contactId = 0, $visibility = FALSE) {
283 $group = new CRM_Contact_DAO_Group();
284
285 $select = $from = $where = '';
286
287 $select = 'SELECT DISTINCT civicrm_group.id, civicrm_group.title ';
288 $from = ' FROM civicrm_group ';
289 $where = " WHERE civicrm_group.is_active = 1 ";
290 if ($contactId) {
291 $from .= ' , civicrm_group_contact ';
292 $where .= " AND civicrm_group.id = civicrm_group_contact.group_id
293 AND civicrm_group_contact.contact_id = " . CRM_Utils_Type::escape($contactId, 'Integer');
294 }
295
296 if ($visibility) {
297 $where .= " AND civicrm_group.visibility != 'User and User Admin Only'";
298 }
299
300 $orderby = " ORDER BY civicrm_group.name";
301 $sql = $select . $from . $where . $orderby;
302
303 $group->query($sql);
304
305 $values = array();
306 while ($group->fetch()) {
307 $values[$group->id] = $group->title;
308 }
309
310 return $values;
311 }
312
313 /**
314 * Function to get the list of groups for contact based on status of group membership
315 *
316 * @param int $contactId contact id
317 * @param string $status state of membership
318 * @param int $numGroupContact number of groups for a contact that should be shown
319 * @param boolean $count true if we are interested only in the count
320 * @param boolean $ignorePermission true if we should ignore permissions for the current user
321 * useful in profile where permissions are limited for the user. If left
322 * at false only groups viewable by the current user are returned
323 * @param boolean $onlyPublicGroups true if we want to hide system groups
324 *
325 * @param bool $excludeHidden
326 *
327 * @return array (reference )|int $values the relevant data object values for the contact or
328 * the total count when $count is true
329 *
330 * $access public
331 */
332 static function &getContactGroup(
333 $contactId,
334 $status = NULL,
335 $numGroupContact = NULL,
336 $count = FALSE,
337 $ignorePermission = FALSE,
338 $onlyPublicGroups = FALSE,
339 $excludeHidden = TRUE
340 ) {
341 if ($count) {
342 $select = 'SELECT count(DISTINCT civicrm_group_contact.id)';
343 }
344 else {
345 $select = 'SELECT
346 civicrm_group_contact.id as civicrm_group_contact_id,
347 civicrm_group.title as group_title,
348 civicrm_group.visibility as visibility,
349 civicrm_group_contact.status as status,
350 civicrm_group.id as group_id,
351 civicrm_group.is_hidden as is_hidden,
352 civicrm_subscription_history.date as date,
353 civicrm_subscription_history.method as method';
354 }
355
356 $where = " WHERE contact_a.id = %1 AND civicrm_group.is_active = 1 ";
357
358 if ($excludeHidden) {
359 $where .= " AND civicrm_group.is_hidden = 0 ";
360 }
361
362 $params = array(1 => array($contactId, 'Integer'));
363 if (!empty($status)) {
364 $where .= ' AND civicrm_group_contact.status = %2';
365 $params[2] = array($status, 'String');
366 }
367 $tables = array(
368 'civicrm_group_contact' => 1,
369 'civicrm_group' => 1,
370 'civicrm_subscription_history' => 1,
371 );
372 $whereTables = array();
373 if ($ignorePermission) {
374 $permission = ' ( 1 ) ';
375 }
376 else {
377 $permission = CRM_Core_Permission::getPermissionedStaticGroupClause(CRM_Core_Permission::VIEW, $tables, $whereTables);
378 }
379
380 $from = CRM_Contact_BAO_Query::fromClause($tables);
381
382 $where .= " AND $permission ";
383
384 if ($onlyPublicGroups) {
385 $where .= " AND civicrm_group.visibility != 'User and User Admin Only' ";
386 }
387
388 $order = $limit = '';
389 if (!$count) {
390 $order = ' ORDER BY civicrm_group.title, civicrm_subscription_history.date ASC';
391
392 if ($numGroupContact) {
393 $limit = " LIMIT 0, $numGroupContact";
394 }
395 }
396
397 $sql = $select . $from . $where . $order . $limit;
398
399 if ($count) {
400 $result = CRM_Core_DAO::singleValueQuery($sql, $params);
401 return $result;
402 }
403 else {
404 $dao = CRM_Core_DAO::executeQuery($sql, $params);
405 $values = array();
406 while ($dao->fetch()) {
407 $id = $dao->civicrm_group_contact_id;
408 $values[$id]['id'] = $id;
409 $values[$id]['group_id'] = $dao->group_id;
410 $values[$id]['title'] = $dao->group_title;
411 $values[$id]['visibility'] = $dao->visibility;
412 $values[$id]['is_hidden'] = $dao->is_hidden;
413 switch ($dao->status) {
414 case 'Added':
415 $prefix = 'in_';
416 break;
417
418 case 'Removed':
419 $prefix = 'out_';
420 break;
421
422 default:
423 $prefix = 'pending_';
424 }
425 $values[$id][$prefix . 'date'] = $dao->date;
426 $values[$id][$prefix . 'method'] = $dao->method;
427 if ($status == 'Removed') {
428 $query = "SELECT `date` as `date_added` FROM civicrm_subscription_history WHERE id = (SELECT max(id) FROM civicrm_subscription_history WHERE contact_id = %1 AND status = \"Added\" AND group_id = $dao->group_id )";
429 $dateDAO = CRM_Core_DAO::executeQuery($query, $params);
430 if ($dateDAO->fetch()) {
431 $values[$id]['date_added'] = $dateDAO->date_added;
432 }
433 }
434 }
435 return $values;
436 }
437 }
438
439 /**
440 * Returns membership details of a contact for a group
441 *
442 * @param int $contactId id of the contact
443 * @param int $groupID Id of a perticuler group
444 * @param string $method If we want the subscription history details for a specific method
445 *
446 * @return object of group contact
447 * @access public
448 * @static
449 */
450 static function getMembershipDetail($contactId, $groupID, $method = 'Email') {
451 $leftJoin = $where = $orderBy = null;
452
453 if ($method) {
454 //CRM-13341 add group_id clause
455 $leftJoin = "
456 LEFT JOIN civicrm_subscription_history
457 ON ( civicrm_group_contact.contact_id = civicrm_subscription_history.contact_id
458 AND civicrm_subscription_history.group_id = {$groupID} )";
459 $where = "AND civicrm_subscription_history.method ='Email'";
460 $orderBy = "ORDER BY civicrm_subscription_history.id DESC";
461 }
462 $query = "
463 SELECT *
464 FROM civicrm_group_contact
465 $leftJoin
466 WHERE civicrm_group_contact.contact_id = %1
467 AND civicrm_group_contact.group_id = %2
468 $where
469 $orderBy
470 ";
471
472 $params = array(
473 1 => array($contactId, 'Integer'),
474 2 => array($groupID, 'Integer'),
475 );
476 $dao = CRM_Core_DAO::executeQuery($query, $params);
477 $dao->fetch();
478 return $dao;
479 }
480
481 /**
482 * Method to get Group Id
483 *
484 * @param int $groupContactID Id of a perticuler group
485 *
486 *
487 * @return groupID
488 * @access public
489 * @static
490 */
491 static function getGroupId($groupContactID) {
492 $dao = new CRM_Contact_DAO_GroupContact();
493 $dao->id = $groupContactID;
494 $dao->find(TRUE);
495 return $dao->group_id;
496 }
497
498 /**
499 * takes an associative array and creates / removes
500 * contacts from the groups
501 *
502 *
503 * @param array $params (reference ) an assoc array of name/value pairs
504 * @param array $contactId contact id
505 *
506 * @param bool $visibility
507 * @param string $method
508 *
509 * @return void
510 * @access public
511 * @static
512 */
513 static function create(&$params, $contactId, $visibility = FALSE, $method = 'Admin') {
514 $contactIds = array();
515 $contactIds[] = $contactId;
516
517 //if $visibility is true we are coming in via profile mean $method = 'Web'
518 $ignorePermission = FALSE;
519 if ($visibility) {
520 $ignorePermission = TRUE;
521 }
522
523 if ($contactId) {
524 $contactGroupList = &CRM_Contact_BAO_GroupContact::getContactGroup($contactId, 'Added',
525 NULL, FALSE, $ignorePermission
526 );
527 if (is_array($contactGroupList)) {
528 foreach ($contactGroupList as $key) {
529 $groupId = $key['group_id'];
530 $contactGroup[$groupId] = $groupId;
531 }
532 }
533 }
534
535 // get the list of all the groups
536 $allGroup = CRM_Contact_BAO_GroupContact::getGroupList(0, $visibility);
537
538 // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
539 if (!is_array($params)) {
540 $params = array();
541 }
542
543 // this fix is done to prevent warning generated by array_key_exits incase of empty array is given as input
544 if (!isset($contactGroup) || !is_array($contactGroup)) {
545 $contactGroup = array();
546 }
547
548 // check which values has to be add/remove contact from group
549 foreach ($allGroup as $key => $varValue) {
550 if (!empty($params[$key]) && !array_key_exists($key, $contactGroup)) {
551 // add contact to group
552 CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $key, $method);
553 }
554 elseif (empty($params[$key]) && array_key_exists($key, $contactGroup)) {
555 // remove contact from group
556 CRM_Contact_BAO_GroupContact::removeContactsFromGroup($contactIds, $key, $method);
557 }
558 }
559 }
560
561 static function isContactInGroup($contactID, $groupID) {
562 if (!CRM_Utils_Rule::positiveInteger($contactID) ||
563 !CRM_Utils_Rule::positiveInteger($groupID)
564 ) {
565 return FALSE;
566 }
567
568 $params = array(
569 array('group', 'IN', array($groupID => 1), 0, 0),
570 array('contact_id', '=', $contactID, 0, 0),
571 );
572 list($contacts, $_) = CRM_Contact_BAO_Query::apiQuery($params, array('contact_id'));
573
574 if (!empty($contacts)) {
575 return TRUE;
576 }
577 return FALSE;
578 }
579
580 /**
581 * Function merges the groups from otherContactID to mainContactID
582 * along with subscription history
583 *
584 * @param int $mainContactId contact id of main contact record.
585 * @param int $otherContactId contact id of record which is going to merge.
586 *
587 * @see CRM_Dedupe_Merger::cpTables()
588 *
589 * TODO: use the 3rd $sqls param to append sql statements rather than executing them here
590 *
591 * @return void.
592 * @static
593 */
594 static function mergeGroupContact($mainContactId, $otherContactId) {
595 $params = array(1 => array($mainContactId, 'Integer'),
596 2 => array($otherContactId, 'Integer'),
597 );
598
599 // find all groups that are in otherContactID but not in mainContactID, copy them over
600 $sql = "
601 SELECT cOther.group_id
602 FROM civicrm_group_contact cOther
603 LEFT JOIN civicrm_group_contact cMain ON cOther.group_id = cMain.group_id AND cMain.contact_id = %1
604 WHERE cOther.contact_id = %2
605 AND cMain.contact_id IS NULL
606 ";
607 $dao = CRM_Core_DAO::executeQuery($sql, $params);
608
609 $otherGroupIDs = array();
610 while ($dao->fetch()) {
611 $otherGroupIDs[] = $dao->group_id;
612 }
613
614 if (!empty($otherGroupIDs)) {
615 $otherGroupIDString = implode(',', $otherGroupIDs);
616
617 $sql = "
618 UPDATE civicrm_group_contact
619 SET contact_id = %1
620 WHERE contact_id = %2
621 AND group_id IN ( $otherGroupIDString )
622 ";
623 CRM_Core_DAO::executeQuery($sql, $params);
624
625 $sql = "
626 UPDATE civicrm_subscription_history
627 SET contact_id = %1
628 WHERE contact_id = %2
629 AND group_id IN ( $otherGroupIDString )
630 ";
631 CRM_Core_DAO::executeQuery($sql, $params);
632 }
633
634 $sql = "
635 SELECT cOther.group_id as group_id,
636 cOther.status as group_status
637 FROM civicrm_group_contact cMain
638 INNER JOIN civicrm_group_contact cOther ON cMain.group_id = cOther.group_id
639 WHERE cMain.contact_id = %1
640 AND cOther.contact_id = %2
641 ";
642 $dao = CRM_Core_DAO::executeQuery($sql, $params);
643
644 $groupIDs = array();
645 while ($dao->fetch()) {
646 // only copy it over if it has added status and migrate the history
647 if ($dao->group_status == 'Added') {
648 $groupIDs[] = $dao->group_id;
649 }
650 }
651
652 if (!empty($groupIDs)) {
653 $groupIDString = implode(',', $groupIDs);
654
655 $sql = "
656 UPDATE civicrm_group_contact
657 SET status = 'Added'
658 WHERE contact_id = %1
659 AND group_id IN ( $groupIDString )
660 ";
661 CRM_Core_DAO::executeQuery($sql, $params);
662
663 $sql = "
664 UPDATE civicrm_subscription_history
665 SET contact_id = %1
666 WHERE contact_id = %2
667 AND group_id IN ( $groupIDString )
668 ";
669 CRM_Core_DAO::executeQuery($sql, $params);
670 }
671
672 // delete all the other group contacts
673 $sql = "
674 DELETE
675 FROM civicrm_group_contact
676 WHERE contact_id = %2
677 ";
678 CRM_Core_DAO::executeQuery($sql, $params);
679
680 $sql = "
681 DELETE
682 FROM civicrm_subscription_history
683 WHERE contact_id = %2
684 ";
685 CRM_Core_DAO::executeQuery($sql, $params);
686 }
687
688 /**
689 * Given an array of contact ids, add all the contacts to the group
690 *
691 * @param $contactIDs
692 * @param $groupID
693 * @param string $method
694 * @param string $status
695 * @param null $tracking
696 * @internal param array $contactIds (reference ) the array of contact ids to be added
697 * @internal param int $groupId the id of the group
698 *
699 * @return array (total, added, notAdded) count of contacts added to group
700 * @access public
701 * @static
702 */
703 static function bulkAddContactsToGroup(
704 $contactIDs,
705 $groupID,
706 $method = 'Admin',
707 $status = 'Added',
708 $tracking = NULL
709 ) {
710
711 $numContactsAdded = 0;
712 $numContactsNotAdded = 0;
713
714 $contactGroupSQL = "
715 REPLACE INTO civicrm_group_contact ( group_id, contact_id, status )
716 VALUES
717 ";
718 $subscriptioHistorySQL = "
719 INSERT INTO civicrm_subscription_history( group_id, contact_id, date, method, status, tracking )
720 VALUES
721 ";
722
723 $date = date('YmdHis');
724
725 // to avoid long strings, lets do BULK_INSERT_HIGH_COUNT values at a time
726 while (!empty($contactIDs)) {
727 $input = array_splice($contactIDs, 0, CRM_Core_DAO::BULK_INSERT_HIGH_COUNT);
728 $contactStr = implode(',', $input);
729
730 // lets check their current status
731 $sql = "
732 SELECT GROUP_CONCAT(contact_id) as contactStr
733 FROM civicrm_group_contact
734 WHERE group_id = %1
735 AND status = %2
736 AND contact_id IN ( $contactStr )
737 ";
738 $params = array(1 => array($groupID, 'Integer'),
739 2 => array($status, 'String'),
740 );
741
742 $presentIDs = array();
743 $dao = CRM_Core_DAO::executeQuery($sql, $params);
744 if ($dao->fetch()) {
745 $presentIDs = explode(',', $dao->contactStr);
746 $presentIDs = array_flip($presentIDs);
747 }
748
749 $gcValues = $shValues = array();
750 foreach ($input as $cid) {
751 if (isset($presentIDs[$cid])) {
752 $numContactsNotAdded++;
753 continue;
754 }
755
756 $gcValues[] = "( $groupID, $cid, '$status' )";
757 $shValues[] = "( $groupID, $cid, '$date', '$method', '$status', '$tracking' )";
758 $numContactsAdded++;
759 }
760
761 if (!empty($gcValues)) {
762 $cgSQL = $contactGroupSQL . implode(",\n", $gcValues);
763 CRM_Core_DAO::executeQuery($cgSQL);
764
765 $shSQL = $subscriptioHistorySQL . implode(",\n", $shValues);
766 CRM_Core_DAO::executeQuery($shSQL);
767 }
768 }
769
770 return array($numContactsAdded, $numContactsNotAdded);
771 }
772 }
773