}
function update_crm_person($id, $ref, $name, $name2, $address, $phone, $phone2, $fax, $email,
}
function update_crm_person($id, $ref, $name, $name2, $address, $phone, $phone2, $fax, $email,
- $lang, $notes, $cat_ids, $entity=null)
+ $lang, $notes, $cat_ids, $entity=null, $type=null)
{
$sql = "UPDATE ".TB_PREF."crm_persons SET "
."ref=".db_escape($ref) . ", "
{
$sql = "UPDATE ".TB_PREF."crm_persons SET "
."ref=".db_escape($ref) . ", "
- if(!update_person_contacts($id, $cat_ids, $entity))
+ if(!update_person_contacts($id, $cat_ids, $entity, $type))
-function update_person_contacts($id, $cat_ids, $entity_id=null)
+function update_person_contacts($id, $cat_ids, $entity_id=null, $type=null)
$sql = "INSERT INTO ".TB_PREF."crm_contacts (person_id,type,action,entity_id)
SELECT ".db_escape($id).",t.type, t.action,".db_escape($entity_id, true)."
FROM ".TB_PREF."crm_categories t WHERE t.id=".implode(' OR t.id=', $cat_ids);
$sql = "INSERT INTO ".TB_PREF."crm_contacts (person_id,type,action,entity_id)
SELECT ".db_escape($id).",t.type, t.action,".db_escape($entity_id, true)."
FROM ".TB_PREF."crm_categories t WHERE t.id=".implode(' OR t.id=', $cat_ids);
$res = get_crm_persons($class, null, $entity, null, true);
$res = get_crm_persons($class, null, $entity, null, true);
- delete_crm_person($person['id'], true);
+ $rels = get_person_contacts($person['id']);
+ if (count($rels) == 0) {
+ delete_crm_person($person['id']);
+ }
-function delete_crm_contacts($person_id, $type = null, $entity_id=null, $action = null)
+function delete_crm_contacts($person_id = null, $type = null, $entity_id=null, $action = null)