Merge addressbooks.
This commit is contained in:
parent
dd3208fe6f
commit
4c638f101e
|
@ -7,35 +7,23 @@
|
|||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
|
||||
OCP\JSON::checkLoggedIn();
|
||||
OCP\JSON::checkAppEnabled('contacts');
|
||||
OCP\JSON::callCheck();
|
||||
|
||||
$ids = $_POST['ids'];
|
||||
$id = intval($_POST['id']);
|
||||
$aid = intval($_POST['aid']);
|
||||
$isaddressbook = isset($_POST['isaddressbook']) ? true: false;
|
||||
|
||||
// Ownership checking
|
||||
OC_Contacts_App::getAddressbook($aid);
|
||||
|
||||
if(!is_array($ids)) {
|
||||
$ids = array($ids,);
|
||||
}
|
||||
$goodids = array();
|
||||
foreach ($ids as $id){
|
||||
try {
|
||||
$card = OC_Contacts_App::getContactObject( intval($id) );
|
||||
if($card) {
|
||||
$goodids[] = $id;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
OCP\Util::writeLog('contacts', 'Error moving contact "'.$id.'" to addressbook "'.$aid.'"'.$e->getMessage(), OCP\Util::ERROR);
|
||||
}
|
||||
}
|
||||
try {
|
||||
OC_Contacts_VCard::moveToAddressBook($aid, $ids);
|
||||
OC_Contacts_VCard::moveToAddressBook($aid, $id, $isaddressbook);
|
||||
} catch (Exception $e) {
|
||||
$msg = $e->getMessage();
|
||||
OCP\Util::writeLog('contacts', 'Error moving contacts "'.implode(',', $ids).'" to addressbook "'.$aid.'"'.$msg, OCP\Util::ERROR);
|
||||
OCP\Util::writeLog('contacts', 'Error moving contacts "'.implode(',', $id).'" to addressbook "'.$aid.'"'.$msg, OCP\Util::ERROR);
|
||||
OC_JSON::error(array('data' => array('message' => $msg,)));
|
||||
}
|
||||
|
||||
OC_JSON::success(array('data' => array('ids' => $goodids,)));
|
||||
|
||||
OC_JSON::success(array('data' => array('ids' => $id,)));
|
|
@ -1437,8 +1437,12 @@ OC.Contacts={
|
|||
if(dragitem.data('bookid') == droptarget.data('id')) {
|
||||
return false;
|
||||
}
|
||||
var droplist = (droptarget.is('ul'))?droptarget:droptarget.next();
|
||||
$.post(OC.filePath('contacts', 'ajax', 'contact/move.php'), { ids: dragitem.data('id'), aid: droptarget.data('id') },
|
||||
var droplist = (droptarget.is('ul')) ? droptarget : droptarget.next();
|
||||
$.post(OC.filePath('contacts', 'ajax', 'contact/move.php'),
|
||||
{
|
||||
id: dragitem.data('id'),
|
||||
aid: droptarget.data('id')
|
||||
},
|
||||
function(jsondata){
|
||||
if(jsondata.status == 'success'){
|
||||
dragitem.attr('data-bookid', droptarget.data('id'))
|
||||
|
@ -1454,7 +1458,27 @@ OC.Contacts={
|
|||
});
|
||||
},
|
||||
dropAddressbook:function(event, dragitem, droptarget) {
|
||||
alert('Dropping address books not implemented yet');
|
||||
if(confirm(t('contacts', 'Do you want to merge these address books?'))) {
|
||||
if(dragitem.data('bookid') == droptarget.data('id')) {
|
||||
return false;
|
||||
}
|
||||
var droplist = (droptarget.is('ul')) ? droptarget : droptarget.next();
|
||||
$.post(OC.filePath('contacts', 'ajax', 'contact/move.php'),
|
||||
{
|
||||
id: dragitem.data('id'),
|
||||
aid: droptarget.data('id'),
|
||||
isaddressbook: 1
|
||||
},
|
||||
function(jsondata){
|
||||
if(jsondata.status == 'success'){
|
||||
OC.Contacts.Contacts.update(); // Easier to refresh the whole bunch.
|
||||
} else {
|
||||
OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error'));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @params params An object with the properties 'contactlist':a jquery object of the ul to insert into,
|
||||
|
|
|
@ -589,7 +589,7 @@ class OC_Contacts_VCard{
|
|||
* @return boolean
|
||||
*
|
||||
*/
|
||||
public static function moveToAddressBook($aid, $id) {
|
||||
public static function moveToAddressBook($aid, $id, $isAddressbook = false) {
|
||||
OC_Contacts_App::getAddressbook($aid); // check for user ownership.
|
||||
if(is_array($id)) {
|
||||
$id_sql = join(',', array_fill(0, count($id), '?'));
|
||||
|
@ -606,8 +606,13 @@ class OC_Contacts_VCard{
|
|||
return false;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
$stmt = null;
|
||||
if($isAddressbook) {
|
||||
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE addressbookid = ?' );
|
||||
} else {
|
||||
$stmt = OCP\DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?' );
|
||||
}
|
||||
try {
|
||||
$result = $stmt->execute(array($aid, $id));
|
||||
} catch(Exception $e) {
|
||||
OCP\Util::writeLog('contacts', __CLASS__.'::'.__METHOD__.', exception: '.$e->getMessage(), OCP\Util::DEBUG);
|
||||
|
|
Loading…
Reference in New Issue