From b6aa5d2875bf171a7cf508102ef16f42b47b984a Mon Sep 17 00:00:00 2001
From: Michael Gapczynski <mtgap@owncloud.com>
Date: Tue, 31 Jul 2012 21:05:00 -0400
Subject: [PATCH] Include contacts in share with search

---
 core/ajax/share.php  | 14 +++++++++++++-
 lib/public/share.php |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/core/ajax/share.php b/core/ajax/share.php
index c613baa7f5..905c28a1c2 100644
--- a/core/ajax/share.php
+++ b/core/ajax/share.php
@@ -66,8 +66,20 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['item']
 			break;
 		case 'getShareWith':
 			if (isset($_GET['search'])) {
-				// TODO Include contacts
 				$shareWith = array();
+				if (OC_App::isEnabled('contacts')) {
+					// TODO Add function to contacts to only get the 'fullname' column to improve performance
+					$ids = OC_Contacts_Addressbook::activeIds();
+					foreach ($ids as $id) {
+						$vcards = OC_Contacts_VCard::all($id);
+						foreach ($vcards as $vcard) {
+							$contact = $vcard['fullname'];
+							if (stripos($contact, $_GET['search']) !== false && (!isset($_GET['itemShares'][OCP\Share::SHARE_TYPE_CONTACT]) || !in_array($contact, $_GET['itemShares'][OCP\Share::SHARE_TYPE_CONTACT]))) {
+								$shareWith[] = array('label' => $contact, 'value' => array('shareType' => 5, 'shareWith' => $contact));
+							}
+						}
+					}
+				}
 				$count = 0;
 				$users = array();
 				$limit = 0;
diff --git a/lib/public/share.php b/lib/public/share.php
index 3053da47e8..47181c8c1f 100644
--- a/lib/public/share.php
+++ b/lib/public/share.php
@@ -34,6 +34,9 @@ class Share {
 	const SHARE_TYPE_USER = 0;
 	const SHARE_TYPE_GROUP = 1;
 	const SHARE_TYPE_PRIVATE_LINK = 3;
+	const SHARE_TYPE_EMAIL = 4;
+	const SHARE_TYPE_CONTACT = 5;
+	const SHARE_TYPE_REMOTE = 6;
 
 	/** CRUDS permissions (Create, Read, Update, Delete, Share) using a bitmask
 	* Construct permissions for share() and setPermissions with Or (|) e.g. Give user read and update permissions: PERMISSION_READ | PERMISSION_UPDATE
-- 
GitLab