+function is_component_already_on_bom($component, $workcentre_added, $loc_code, $selected_parent)
+{
+ $sql = "SELECT component
+ FROM ".TB_PREF."bom
+ WHERE parent=".db_escape($selected_parent)."
+ AND component=".db_escape($component) . "
+ AND workcentre_added=".db_escape($workcentre_added) . "
+ AND loc_code=".db_escape($loc_code);
+ $result = db_query($sql,"check failed");
+
+ return (db_num_rows($result) > 0);
+}
+
+//--------------------------------------------------------------------------------------
+
+function check_for_recursive_bom($ultimate_parent, $component_to_check)
+{
+
+ /* returns true ie 1 if the bom contains the parent part as a component
+ ie the bom is recursive otherwise false ie 0 */
+
+ $sql = "SELECT component FROM ".TB_PREF."bom WHERE parent=".db_escape($component_to_check);
+ $result = db_query($sql,"could not check recursive bom");
+
+ if ($result)
+ {
+ while ($myrow = db_fetch_row($result))
+ {
+ if ($myrow[0] == $ultimate_parent)
+ {
+ return 1;
+ }
+
+ if (check_for_recursive_bom($ultimate_parent, $myrow[0]))
+ {
+ return 1;
+ }
+ }
+ }
+
+ return 0;
+}
+