function get_records_from_domain_id($id, $rowstart = 0, $rowamount = 999999, $sortby = 'name')
{
    global $db;
    $result = array();
    if (is_numeric($id)) {
        if (isset($_SESSION[$id . "_ispartial"]) && $_SESSION[$id . "_ispartial"] == 1) {
            $db->setLimit($rowamount, $rowstart);
            $result = $db->query("SELECT record_owners.record_id as id\n\t\t\t\t\tFROM record_owners,domains,records\n\t\t\t\t\tWHERE record_owners.user_id = " . $db->quote($_SESSION["userid"], 'integer') . "\n\t\t\t\t\tAND record_owners.record_id = records.id\n\t\t\t\t\tAND records.domain_id = " . $db->quote($id, 'integer') . "\n\t\t\t\t\tGROUP BY record_owners.record_id ORDER BY records." . $sortby);
            $ret = array();
            if ($result->numRows() == 0) {
                return -1;
            } else {
                $ret[] = array();
                $retcount = 0;
                while ($r = $result->fetchRow()) {
                    // Call get_record_from_id for each row.
                    $ret[$retcount] = get_record_from_id($r["id"]);
                    $retcount++;
                }
                $result = $ret;
            }
        } else {
            $db->setLimit($rowamount, $rowstart);
            $result = $db->query("SELECT id FROM records WHERE domain_id=" . $db->quote($id, 'integer') . " ORDER BY records." . $sortby);
            $ret = array();
            if ($result->numRows() == 0) {
                return -1;
            } else {
                $ret[] = array();
                $retcount = 0;
                while ($r = $result->fetchRow()) {
                    // Call get_record_from_id for each row.
                    $ret[$retcount] = get_record_from_id($r["id"]);
                    $retcount++;
                }
                $result = $ret;
            }
            $result = order_domain_results($result, $sortby);
            return $result;
        }
    } else {
        error(sprintf(ERR_INV_ARG, "get_records_from_domain_id"));
    }
}
Example #2
0
/** Get all records from a domain id.
 *
 * Retrieve all fields of the records and send it back to the function caller.
 *
 * @param int $id Domain ID
 * @param int $rowstart Starting row [default=0]
 * @param int $rowamount Number of rows to return in this query [default=999999]
 * @param string $sortby Column to sort by [default='name']
 *
 * @return int|mixed[] array of record detail, or -1 if nothing found
 */
function get_records_from_domain_id($id, $rowstart = 0, $rowamount = 999999, $sortby = 'name')
{
    global $db;
    global $db_type;
    $result = array();
    if (is_numeric($id)) {
        if (isset($_SESSION[$id . "_ispartial"]) && $_SESSION[$id . "_ispartial"] == 1) {
            $db->setLimit($rowamount, $rowstart);
            $result = $db->query("SELECT record_owners.record_id as id\n\t\t\t\t\tFROM record_owners,domains,records\n\t\t\t\t\tWHERE record_owners.user_id = " . $db->quote($_SESSION["userid"], 'integer') . "\n\t\t\t\t\tAND record_owners.record_id = records.id\n\t\t\t\t\tAND records.domain_id = " . $db->quote($id, 'integer') . "\n\t\t\t\t\tGROUP BY record_owners.record_id ORDER BY records." . $sortby);
            $ret = array();
            if ($result) {
                $ret[] = array();
                $retcount = 0;
                while ($r = $result->fetchRow()) {
                    // Call get_record_from_id for each row.
                    $fields = get_record_from_id($r["id"]);
                    if ($fields == -1) {
                        continue;
                    }
                    $ret[$retcount] = $fields;
                    $retcount++;
                }
                $result = $ret;
            } else {
                return -1;
            }
        } else {
            $db->setLimit($rowamount, $rowstart);
            $natural_sort = 'LENGTH(records.name), records.name';
            if ($db_type == 'mysql' || $db_type == 'mysqli' || $db_type == 'sqlite' || $db_type == 'sqlite3') {
                $natural_sort = 'records.name+0<>0 DESC, records.name+0, records.name';
            }
            $sql_sortby = $sortby == 'name' ? $natural_sort : $sortby . ', ' . $natural_sort;
            $result = $db->query("SELECT id FROM records WHERE domain_id=" . $db->quote($id, 'integer') . " AND type IS NOT NULL ORDER BY " . $sql_sortby);
            $ret = array();
            if ($result) {
                $ret[] = array();
                $retcount = 0;
                while ($r = $result->fetchRow()) {
                    // Call get_record_from_id for each row.
                    $fields = get_record_from_id($r["id"]);
                    if ($fields == -1) {
                        continue;
                    }
                    $ret[$retcount] = $fields;
                    $retcount++;
                }
                $result = $ret;
            } else {
                return -1;
            }
            $result = order_domain_results($result, $sortby);
            return $result;
        }
    } else {
        error(sprintf(ERR_INV_ARG, "get_records_from_domain_id"));
    }
}
Example #3
0
/** Get all records from a domain id.
 *
 * Retrieve all fields of the records and send it back to the function caller.
 *
 * @param int $id Domain ID
 * @param int $rowstart Starting row [default=0]
 * @param int $rowamount Number of rows to return in this query [default=999999]
 * @param string $sortby Column to sort by [default='name']
 *
 * @return int|mixed[] array of record detail, or -1 if nothing found
 */
function get_records_from_domain_id($id, $rowstart = 0, $rowamount = 999999, $sortby = 'name')
{
    global $db;
    global $db_type;
    $result = array();
    if (is_numeric($id)) {
        if (isset($_SESSION[$id . "_ispartial"]) && $_SESSION[$id . "_ispartial"] == 1) {
            $db->setLimit($rowamount, $rowstart);
            $result = $db->query("SELECT records.id, domains.id, records.name, records.type, records.content, records.ttl, records.prio, records.change_date\n                                    FROM record_owners,domains,records\n                                    WHERE record_owners.user_id = " . $db->quote($_SESSION["userid"], 'integer') . "\n                                    AND record_owners.record_id = records.id\n                                    AND records.domain_id = " . $db->quote($id, 'integer') . "\n                                    GROUP BY records.id, domains.id, records.name, records.type, records.content, records.ttl, records.prio, records.change_date\n                                    ORDER BY type = 'SOA' DESC, type = 'NS' DESC, records." . $sortby);
            if ($result) {
                while ($r = $result->fetchRow()) {
                    $ret[] = array("id" => $r["id"], "domain_id" => $r["domain_id"], "name" => $r["name"], "type" => $r["type"], "content" => $r["content"], "ttl" => $r["ttl"], "prio" => $r["prio"], "change_date" => $r["change_date"]);
                }
                $result = $ret;
            } else {
                return -1;
            }
        } else {
            $db->setLimit($rowamount, $rowstart);
            $natural_sort = 'records.name';
            if ($db_type == 'mysql' || $db_type == 'mysqli' || $db_type == 'sqlite' || $db_type == 'sqlite3') {
                $natural_sort = 'records.name+0<>0 DESC, records.name+0, records.name';
            }
            $sql_sortby = $sortby == 'name' ? $natural_sort : $sortby . ', ' . $natural_sort;
            $result = $db->query("SELECT id, domain_id, name, type, content, ttl, prio, change_date\n                                    FROM records \n                                    WHERE domain_id=" . $db->quote($id, 'integer') . " AND type IS NOT NULL\n                                    ORDER BY type = 'SOA' DESC, type = 'NS' DESC," . $sql_sortby);
            $ret = array();
            if ($result) {
                while ($r = $result->fetchRow()) {
                    $ret[] = array("id" => $r["id"], "domain_id" => $r["domain_id"], "name" => $r["name"], "type" => $r["type"], "content" => $r["content"], "ttl" => $r["ttl"], "prio" => $r["prio"], "change_date" => $r["change_date"]);
                }
                $result = $ret;
            } else {
                return -1;
            }
            $result = order_domain_results($result, $sortby);
            return $result;
        }
    } else {
        error(sprintf(ERR_INV_ARG, "get_records_from_domain_id"));
    }
}