function deleteItem($table, $attributeid, $delete)
{
    global $tables, $replace;
    # delete the index in delete
    $valreq = Sql_Fetch_Row_query("select name from {$table} where id = {$delete}");
    $val = $valreq[0];
    # check dependencies
    $dependencies = array();
    $result = Sql_query("select distinct userid from {$tables['user_attribute']} where\n  attributeid = {$attributeid} and value = {$delete}");
    while ($row = Sql_fetch_array($result)) {
        array_push($dependencies, $row["userid"]);
    }
    if (sizeof($dependencies) == 0) {
        $result = Sql_query("delete from {$table} where id = {$delete}");
    } else {
        if ($replace) {
            $result = Sql_Query("update {$tables['user_attribute']} set value = {$replace} where value = {$delete}");
            $result = Sql_query("delete from {$table} where id = {$delete}");
        } else {
            print $GLOBALS["I18N"]->get("cannotdelete");
            print " <b>{$val}</b><br />";
            print $GLOBALS["I18N"]->get("dependentrecords") . '<p></p>';
            for ($i = 0; $i < sizeof($dependencies); $i++) {
                print PageLink2("user", $GLOBALS["I18N"]->get("user") . " " . $dependencies[$i], "id={$dependencies[$i]}") . "<br />\n";
                if ($i > 10) {
                    print $GLOBALS['I18N']->get('TooManyToList') . "\n " . sizeof($dependencies) . "<br /><br />";
                    giveAlternative($table, $delete, $attributeid);
                    return 0;
                }
            }
            print "</p><br />";
            giveAlternative($table, $delete, $attributeid);
        }
    }
    return 1;
}
function deleteItem($table, $attributeid, $delete)
{
    global $tables, $replace;
    # delete the index in delete
    $valreq = Sql_Fetch_Row_query("select name from {$table} where id = {$delete}");
    $val = $valreq[0];
    # check dependencies
    $dependencies = array();
    $result = Sql_query("select distinct userid from {$tables['user_attribute']} where\n  attributeid = {$attributeid} and value = {$delete}");
    while ($row = Sql_fetch_array($result)) {
        array_push($dependencies, $row["userid"]);
    }
    if (sizeof($dependencies) == 0) {
        $result = Sql_query("delete from {$table} where id = {$delete}");
    } else {
        if ($replace) {
            $result = Sql_Query("update {$tables['user_attribute']} set value = {$replace} where value = {$delete}");
            $result = Sql_query("delete from {$table} where id = {$delete}");
        } else {
            ?>
    Cannot delete <b><?php 
            echo $val;
            ?>
</b><br />
    The Following record(s) are dependent on this value<br />
    Update the record(s) to not use this attribute value and try again<p>
    <?php 
            for ($i = 0; $i < sizeof($dependencies); $i++) {
                print PageLink2("user", "User " . $dependencies[$i], "id={$dependencies[$i]}") . "<br />\n";
                if ($i > 10) {
                    print "* Too many to list, total dependencies:\n " . sizeof($dependencies) . "<br /><br />";
                    giveAlternative($table, $delete, $attributeid);
                    return 0;
                }
            }
            print "</p><br />";
            giveAlternative($table, $delete, $attributeid);
        }
    }
    return 1;
}
function deleteItem($table, $attributeid, $delete)
{
    global $tables;
    if (isset($_REQUEST['replace'])) {
        $replace = sprintf('%d', $_REQUEST['replace']);
    } else {
        $replace = 0;
    }
    # delete the index in delete
    $valreq = Sql_Fetch_Row_query("select name from {$table} where id = {$delete}");
    $val = $valreq[0];
    # check dependencies
    $dependencies = array();
    $result = Sql_query("select distinct userid from {$tables['user_attribute']} where\n  attributeid = {$attributeid} and value = {$delete}");
    while ($row = Sql_fetch_array($result)) {
        array_push($dependencies, $row["userid"]);
    }
    if (sizeof($dependencies) == 0) {
        $result = Sql_query("delete from {$table} where id = {$delete}");
    } else {
        if ($replace) {
            $result = Sql_Query("update {$tables['user_attribute']} set value = {$replace} where value = {$delete}");
            $result = Sql_query("delete from {$table} where id = {$delete}");
        } else {
            print $GLOBALS["I18N"]->get("Cannot delete");
            print " <b>{$val}</b><br />";
            print $GLOBALS["I18N"]->get("The following subscriber(s) are dependent on this value<br />Update the subscriber profiles to not use this attribute value and try again");
            for ($i = 0; $i < sizeof($dependencies); $i++) {
                print PageLink2("user", $GLOBALS["I18N"]->get("user") . " " . $dependencies[$i], "id={$dependencies[$i]}") . "<br />\n";
                if ($i > 10) {
                    print $GLOBALS['I18N']->get('* Too many to list, total dependencies:') . "\n " . sizeof($dependencies) . "<br /><br />";
                    giveAlternative($table, $delete, $attributeid);
                    return 0;
                }
            }
            print "<br />";
            giveAlternative($table, $delete, $attributeid);
        }
    }
    return 1;
}