From 146ff34de158011bed55f2847c1b67756408706a Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 4 Feb 2011 17:29:24 +0000 Subject: [PATCH] Remove category children if that option is chosen --- addressbook/inc/class.addressbook_so.inc.php | 27 ++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/addressbook/inc/class.addressbook_so.inc.php b/addressbook/inc/class.addressbook_so.inc.php index 1c80ab97dc..a313c22f03 100755 --- a/addressbook/inc/class.addressbook_so.inc.php +++ b/addressbook/inc/class.addressbook_so.inc.php @@ -783,12 +783,29 @@ class addressbook_so */ function delete_category($data) { - // Get addresses that use the category - $ids = $this->search(array('cat_id' => $data['cat_id']), array('contact_id', 'cat_id')); - foreach($ids as &$info) + // get all cats if you want to drop sub cats + $drop_subs = ($data['drop_subs'] && !$data['modify_subs']); + if($drop_subs) { - $info['cat_id'] = implode(',',array_diff(explode(',',$info['cat_id']), array($data['cat_id']))); - $this->save($info); + $cats = new categories('', 'addressbook'); + $cat_ids = $cats->return_all_children($data['cat_id']); + } + else + { + $cat_ids = array($data['cat_id']); + } + + // Get addresses that use the category + @set_time_limit( 0 ); + $ids = array(); + foreach($cat_ids as $cat_id) + { + $ids = $this->search(array('cat_id' => $cat_id), array('contact_id', 'cat_id')); + foreach($ids as &$info) + { + $info['cat_id'] = implode(',',array_diff(explode(',',$info['cat_id']), $cat_ids)); + $this->save($info); + } } }