Mysqli errors: Trying to access array offset on value of type bool. Fixed. Please...
[fa-stable.git] / includes / db / crm_contacts_db.inc
index 8623c8e0043525755a07ff8a2248ef76dbc7556e..98862b73ae3c25d2a6ad338a34eef770e38850cb 100644 (file)
@@ -242,7 +242,7 @@ function get_crm_category_name($id)
        $result = db_query($sql, "could not get sales type");
 
        $row = db_fetch_row($result);
-       return $row[0];
+       return is_array($row) ? $row[0] : false;
 }
 
 //----------------------------------------------------------------------------------------
@@ -300,4 +300,16 @@ function get_crm_contact($id)
        return $ret;
 }
 
-?>
\ No newline at end of file
+/*
+        Check for whether category is used in contacts.
+*/
+function is_crm_category_used($id)
+{
+       $row = get_crm_category($id);
+       $sql = "SELECT COUNT(*) FROM ".TB_PREF."crm_contacts WHERE type='".$row['type']."' AND action='".$row['action']."'";
+       $result = db_query($sql, "check relations for crm_contacts failed");
+       $contacts = db_fetch($result);
+       return $contacts[0];
+}
+
+