diff --git a/addressbook/merge.php b/addressbook/merge.php index 4549fdb3d1..54f9f31885 100644 --- a/addressbook/merge.php +++ b/addressbook/merge.php @@ -4,6 +4,13 @@ * * Usage: curl --user $username[:$passwd] -L https://domain.com/egroupware/addressbook/merge.php?path=/templates/addressbook/document.txt&ids=123 * + * Supported GET parameters: + * - path: full VFS path of document to merge + * - ids: one or more id(s): ids[]=123&ids[]=456 + * - search: search criteria or array with field specific criteria, eg. search[account_id]=123 + * - limit: max. number of search results to return, default 1 + * - order: default last modified first + * * For Apache FCGI you need the following rewrite rule: * * RewriteEngine on @@ -35,7 +42,43 @@ require_once($egw_dir.'/phpgwapi/inc/class.egw_digest_auth.inc.php'); include($egw_dir.'/header.inc.php'); $merge = new addressbook_merge(); -if (($err = $merge->download($_REQUEST['path'], $_REQUEST['ids']))) + +if (!isset($_REQUEST['ids']) && isset($_REQUEST['search'])) +{ + if (is_array($_REQUEST['search'])) + { + $criteria = array(); + foreach($_REQUEST['search'] as $name => $value) + { + if (isset($merge->contacts->contact_fields[$name])) + { + $criteria[$name] = $value; + } + } + $wildcard = ''; + } + else + { + $criteria = $_REQUEST['search']; + $wildcard = '*'; + } + $order_by = 'contact_modified DESC'; + if (isset($_REQUEST['order']) && preg_match('/^[a-z0-9_, ]+$/', $_REQUEST['order'])) + { + $order_by = $_REQUEST['order']; + } + $ids = array(); + foreach($merge->contacts->search($criteria, true, $order_by, '', $wildcard, true, 'AND', + array(0, isset($_REQUEST['limit']) && $_REQUEST['limit'] > 1 ? (int)$_REQUEST['limit'] : 1)) as $row) + { + $ids[] = $row['id']; + } +} +else +{ + $ids = (array)$_REQUEST['ids']; +} +if (($err = $merge->download($_REQUEST['path'], $ids))) { header("HTTP/1.1 500 $err"); }