示例#1
0
/**
 * System logs
 */
if (!empty($curSys["name"])) {
    if (isset($_GET["slog_sort"]) && $_GET["slog_sort"] != "undefined") {
        if ($_GET['slog_sort'] == 'asc') {
            $ssort = 'ASC';
        }
        if ($_GET['slog_sort'] == 'desc') {
            $ssort = 'DESC';
        }
    } else {
        $ssort = 'DESC';
    }
    // figure out what coords to calculate from
    $usable_coords = usable_coords();
    $usex = $usable_coords["x"];
    $usey = $usable_coords["y"];
    $usez = $usable_coords["z"];
    $exact = $usable_coords["current"] === true ? "" : " *";
    /*
     *	if log range is set to zero, only show logs from current system
     */
    if ($settings["log_range"] == 0) {
        $log_res = mysqli_query($GLOBALS["___mysqli_ston"], "\tSELECT SQL_CACHE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_log.id, user_log.system_name AS log_system_name, user_log.station_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_log.log_entry, user_log.stardate,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tedtb_systems.name AS system_name,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tedtb_stations.name AS station_name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM user_log\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN edtb_systems ON user_log.system_id = edtb_systems.id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN edtb_stations ON user_log.station_id = edtb_stations.id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE user_log.system_name = '" . mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $curSys["name"]) . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY user_log.stardate " . $ssort . "") or write_log(mysqli_error($GLOBALS["___mysqli_ston"]), __FILE__, __LINE__);
    } elseif ($settings["log_range"] == -1) {
        $log_res = mysqli_query($GLOBALS["___mysqli_ston"], "\tSELECT SQL_CACHE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_log.id, user_log.system_name AS log_system_name, user_log.station_id,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_log.log_entry, user_log.stardate,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsqrt(pow((IFNULL(edtb_systems.x, user_systems_own.x)-(" . $usex . ")),2)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t+pow((IFNULL(edtb_systems.y, user_systems_own.y)-(" . $usey . ")),2)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t+pow((IFNULL(edtb_systems.z, user_systems_own.z)-(" . $usez . ")),2)) AS distance,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tedtb_systems.name AS system_name,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tedtb_stations.name AS station_name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM user_log\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN edtb_systems ON user_log.system_name = edtb_systems.name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN edtb_stations ON user_log.station_id = edtb_stations.id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN user_systems_own ON user_log.system_name = user_systems_own.name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE user_log.system_name != ''\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY user_log.stardate " . $ssort . "") or write_log(mysqli_error($GLOBALS["___mysqli_ston"]), __FILE__, __LINE__);
    } else {
        $log_res = mysqli_query($GLOBALS["___mysqli_ston"], "\tSELECT SQL_CACHE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_log.id, user_log.system_id, user_log.system_name AS log_system_name,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_log.station_id, user_log.log_entry, user_log.stardate,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsqrt(pow((IFNULL(edtb_systems.x, user_systems_own.x)-(" . $usex . ")),2)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t+pow((IFNULL(edtb_systems.y, user_systems_own.y)-(" . $usey . ")),2)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t+pow((IFNULL(edtb_systems.z, user_systems_own.z)-(" . $usez . ")),2)) AS distance,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tedtb_systems.name AS system_name,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tedtb_stations.name AS station_name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM user_log\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN edtb_systems ON user_log.system_name = edtb_systems.name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN edtb_stations ON user_log.station_id = edtb_stations.id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN user_systems_own ON user_log.system_name = user_systems_own.name\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tIFNULL(edtb_systems.x, user_systems_own.x) BETWEEN " . $usex . "-" . $settings["log_range"] . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND " . $usex . "+" . $settings["log_range"] . " &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tIFNULL(edtb_systems.y, user_systems_own.y) BETWEEN " . $usey . "-" . $settings["log_range"] . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND " . $usey . "+" . $settings["log_range"] . " &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tIFNULL(edtb_systems.z, user_systems_own.z) BETWEEN " . $usez . "-" . $settings["log_range"] . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND " . $usez . "+" . $settings["log_range"] . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_log.system_name = '" . mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $curSys["name"]) . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY user_log.system_name = '" . mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $curSys["name"]) . "' DESC,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdistance ASC,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_log.stardate " . $ssort . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 10") or write_log(mysqli_error($GLOBALS["___mysqli_ston"]), __FILE__, __LINE__);
    }
    $num = mysqli_num_rows($log_res);
示例#2
0
文件: functions.php 项目: DBnR1/EDTB
/**
 * Return distance from current to $system
 *
 * @param string|int $system
 * @return string $distance
 * @author Mauri Kujala <*****@*****.**>
 */
function get_distance($system)
{
    global $mysqli;
    /**
     * fetch target coordinates
     */
    $esc_sys = $mysqli->real_escape_string($system);
    $query = "  (SELECT\n                edtb_systems.x AS target_x,\n                edtb_systems.y AS target_y,\n                edtb_systems.z AS target_z\n                FROM edtb_systems\n                WHERE edtb_systems.name = '{$esc_sys}')\n                UNION\n                (SELECT\n                user_systems_own.x AS target_x,\n                user_systems_own.y AS target_y,\n                user_systems_own.z AS target_z\n                FROM user_systems_own\n                WHERE user_systems_own.name = '{$esc_sys}')\n                LIMIT 1";
    $result = $mysqli->query($query) or write_log($mysqli->error, __FILE__, __LINE__);
    $obj = $result->fetch_object();
    $target_x = $obj->target_x;
    $target_y = $obj->target_y;
    $target_z = $obj->target_z;
    $result->close();
    // figure out what coords to calculate from
    $usable_coords = usable_coords();
    $usex = $usable_coords["x"];
    $usey = $usable_coords["y"];
    $usez = $usable_coords["z"];
    $exact = $usable_coords["current"] === true ? "" : " *";
    if (valid_coordinates($target_x, $target_y, $target_z)) {
        $dist = number_format(sqrt(pow($target_x - $usex, 2) + pow($target_y - $usey, 2) + pow($target_z - $usez, 2)), 2);
        $distance = $dist . ' ly' . $exact;
    } else {
        $distance = '';
    }
    return $distance;
}
示例#3
0
文件: functions.php 项目: DBnR1/EDTB
/**
 * Parse data for Data Point
 *
 * @param string $key field name
 * @param string $value field value
 * @param float $d_x x coordinate
 * @param float $d_y y coordinate
 * @param float $d_z z coordinate
 * @param bool $dist
 * @param string $table table name
 * @param bool $enum
 *
 * @return string $this_row parsed html td tag
 * @author Mauri Kujala <*****@*****.**>
 */
function set_data($key, $value, $d_x, $d_y, $d_z, &$dist, $table, $enum)
{
    $this_row = "";
    // Regular Expression filter for links
    $reg_exUrl = "/(http|https|ftp|ftps)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(\\/\\S*)?/";
    $value = $value == "" ? "n/a" : $value;
    /**
     * show distances
     */
    if ($dist !== false) {
        // figure out what coords to calculate from
        $usable_coords = usable_coords();
        $usex = $usable_coords["x"];
        $usey = $usable_coords["y"];
        $usez = $usable_coords["z"];
        $exact = $usable_coords["current"] === true ? "" : " *";
        if (valid_coordinates($d_x, $d_y, $d_z)) {
            $distance = number_format(sqrt(pow($d_x - $usex, 2) + pow($d_y - $usey, 2) + pow($d_z - $usez, 2)), 2);
            $this_row .= '<td class="datapoint_td" style="white-space:nowrap">' . $distance . $exact . '</td>';
        } else {
            $this_row .= '<td class="datapoint_td">n/a</td>';
        }
        $dist = false;
    }
    /**
     * make a link for systems with an id
     */
    if ($key == "system_id" && $value != "0") {
        $this_row .= '<td class="datapoint_td">';
        $this_row .= '<a href="/System?system_id=' . $value . '">' . $value . '</a>';
        $this_row .= '</td>';
    } elseif (strpos($key, "system_name") !== false && $value != "0" || $key == "name" && $table == "edtb_systems") {
        /**
         * provide crosslinks to screenshot gallery, log page, etc
         */
        $item_crosslinks = System::crosslinks($value);
        $this_row .= '<td class="datapoint_td">';
        $this_row .= '<a href="/System?system_name=' . urlencode($value) . '">' . $value . $item_crosslinks . '</a>';
        $this_row .= '</td>';
    } elseif (strpos($key, "price") !== false || strpos($key, "ls") !== false || strpos($key, "population") !== false || strpos($key, "distance") !== false) {
        if (is_numeric($value) && $value != null) {
            $this_row .= '<td class="datapoint_td">' . number_format($value) . '</td>';
        } else {
            $this_row .= '<td class="datapoint_td">n/a</td>';
        }
    } elseif (preg_match($reg_exUrl, $value, $url)) {
        if (mb_strlen($value) >= 80) {
            $urli = substr($value, 0, 80) . "...";
        } else {
            $urli = $value;
        }
        $this_row .= '<td class="datapoint_td">';
        $this_row .= preg_replace($reg_exUrl, '<a href="' . $url[0] . '" target="_blank">' . $urli . '</a> ', $value);
        $this_row .= '</td>';
    } elseif ($enum !== false) {
        switch ($value) {
            case "0":
                $real_value = '<span class="enum_no">&#10799;</span>';
                break;
            case "1":
                $real_value = '<span class="enum_yes">&#10003;</span>';
                break;
            default:
                $real_value = "n/a";
        }
        $this_row .= '<td class="datapoint_td" style="text-align:center">' . $real_value . '</td>';
    } else {
        $this_row .= '<td class="datapoint_td">' . substr(strip_tags($value), 0, 100) . '</td>';
    }
    /**
     *  parse log entries
     */
    if ($key == "log_entry") {
        if (mb_strlen($value) >= 100) {
            $this_row = '<td class="datapoint_td">' . substr(strip_tags($value), 0, 100) . '...</td>';
        } else {
            $this_row = '<td class="datapoint_td">' . $value . '</td>';
        }
    }
    return $this_row;
}
示例#4
0
 function show_list()
 {
     # message after add or edit
     $this->content_saved = $_SESSION['content_saved'];
     $_SESSION['content_saved'] = '';
     # default sort (a = ascending)
     $ad = 'a';
     if ($_GET['sort'] && in_array($_GET['sort'], $this->fields_in_list_view)) {
         if ($_GET['ad'] == 'a') {
             $asc_des = 'ASC';
         }
         if ($_GET['ad'] == 'd') {
             $asc_des = 'DESC';
         }
         $order_by = "ORDER by " . $_GET['sort'] . ' ' . $asc_des;
     } else {
         $order_by = "ORDER by {$this->primary_key} DESC";
     }
     # navigation 1/3
     $start = $_GET["start"];
     if (!$start) {
         $start = 0;
     } else {
         $start *= 1;
     }
     // build query_string
     // query_joomla_component (joomla)
     if ($this->query_joomla_component) {
         $query_string = '&option=' . $this->query_joomla_component;
     }
     // navigation
     $query_string .= '&start=' . $start;
     // sorting
     $query_string .= '&ad=' . $_GET['ad'] . '&sort=' . $_GET['sort'];
     // searching
     $query_string .= '&s=' . $_GET['s'] . '&f=' . $_GET['f'];
     //table
     $query_string .= '&table=' . $_GET['table'] . '';
     # search
     if ($_GET['s'] && $_GET['f']) {
         $in_search = addslashes(stripslashes($_GET['s']));
         $in_search_field = $_GET['f'];
         if ($in_search_field == $this->primary_key) {
             $where_search = "WHERE {$in_search_field} = '{$in_search}' ";
         } else {
             $where_search = "WHERE {$in_search_field} LIKE '%{$in_search}%' ";
         }
     }
     # select
     $sql = "SELECT * FROM `{$this->table}` {$where_search} {$order_by}";
     /*
      *	if sorting by distance
      */
     if ($_GET['sort'] && $_GET['sort'] == "distance") {
         if ($_GET['ad'] == 'a') {
             $asc_des = 'DESC';
         }
         if ($_GET['ad'] == 'd') {
             $asc_des = 'ASC';
         }
         // figure out what coords to calculate from
         $usable_coords = usable_coords();
         $rusex = $usable_coords["x"];
         $rusey = $usable_coords["y"];
         $rusez = $usable_coords["z"];
         $res2 = mysqli_query($GLOBALS["___mysqli_ston"], "\tSHOW COLUMNS\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM `{$this->table}`") or write_log(mysqli_error($GLOBALS["___mysqli_ston"]), __FILE__, __LINE__);
         while ($rij3 = mysqli_fetch_assoc($res2)) {
             $fields[] = $this->table . '.' . $rij3["Field"];
         }
         $fieldss = join(",", $fields);
         if ($asc_des == "DESC") {
             $order_by = "ORDER BY -(sqrt(pow((ritem_coordx-(" . $rusex . ")),2)+pow((ritem_coordy-(" . $rusey . ")),2)+pow((ritem_coordz-(" . $rusez . ")),2)))" . $asc_des;
         } else {
             $order_by = "ORDER BY sqrt(pow((ritem_coordx-(" . $rusex . ")),2)+pow((ritem_coordy-(" . $rusey . ")),2)+pow((ritem_coordz-(" . $rusez . ")),2)) DESC";
         }
         if ($this->table == "edtb_systems") {
             $sql = "SELECT " . $fieldss . ",edtb_systems.x AS ritem_coordx,\n\t\t\t\t\t\t\t\t\t\t\t\tedtb_systems.y AS ritem_coordy,\n\t\t\t\t\t\t\t\t\t\t\t\tedtb_systems.z AS ritem_coordz\n\t\t\t\t\t\t\t\t\t\t\t\tFROM {$this->table}\n\t\t\t\t\t\t\t\t\t\t\t\t{$order_by}";
         } elseif ($this->table == "edtb_stations") {
             $sql = "SELECT " . $fieldss . ",edtb_systems.x AS ritem_coordx,\n\t\t\t\t\t\t\t\t\t\t\t\tedtb_systems.y AS ritem_coordy,\n\t\t\t\t\t\t\t\t\t\t\t\tedtb_systems.z AS ritem_coordz\n\t\t\t\t\t\t\t\t\t\t\t\tFROM {$this->table}\n\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN edtb_systems ON {$this->table}.system_id = edtb_systems.id\n\t\t\t\t\t\t\t\t\t\t\t\t{$order_by}";
         } else {
             $sql = "SELECT " . $fieldss . ",IFNULL(edtb_systems.x, user_systems_own.x) AS ritem_coordx,\n\t\t\t\t\t\t\t\t\t\t\t\tIFNULL(edtb_systems.y, user_systems_own.y) AS ritem_coordy,\n\t\t\t\t\t\t\t\t\t\t\t\tIFNULL(edtb_systems.z, user_systems_own.z) AS ritem_coordz\n\t\t\t\t\t\t\t\t\t\t\t\tFROM {$this->table}\n\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN edtb_systems ON {$this->table}.system_name = edtb_systems.name\n\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN user_systems_own ON {$this->table}.system_name = user_systems_own.name\n\t\t\t\t\t\t\t\t\t\t\t\t{$order_by}";
         }
         //write_log($sql);
     }
     $result = mysqli_query($GLOBALS["___mysqli_ston"], $sql);
     # navigation 2/3
     $hits_total = mysqli_num_rows($result);
     $sql .= " LIMIT {$start}, {$this->num_rows_list_view}";
     $result = mysqli_query($GLOBALS["___mysqli_ston"], $sql) or write_log(mysqli_error($GLOBALS["___mysqli_ston"]), __FILE__, __LINE__);
     if (mysqli_num_rows($result) > 0) {
         $result2 = mysqli_query($GLOBALS["___mysqli_ston"], "SHOW COLUMNS FROM `{$this->table}`") or write_log(mysqli_error($GLOBALS["___mysqli_ston"]), __FILE__, __LINE__);
         while ($rij2 = mysqli_fetch_assoc($result2)) {
             extract($rij2);
             $field_type[$Field] = $Type;
         }
         $count = 0;
         while ($rij = mysqli_fetch_assoc($result)) {
             $count++;
             $this_row = '';
             if ($background == '#38484F') {
                 $background = '#273238';
             } else {
                 $background = '#38484F';
             }
             $dist = false;
             $dist1 = false;
             $exact = "";
             $d_x = "";
             $d_y = "";
             $d_z = "";
             if (array_key_exists("x", $rij) && array_key_exists("y", $rij) && array_key_exists("z", $rij) || array_key_exists("system_name", $rij) || array_key_exists("system_id", $rij)) {
                 $dist = true;
                 $dist1 = true;
                 if (isset($rij["x"]) && isset($rij["y"]) && isset($rij["z"])) {
                     $d_x = $rij["x"];
                     $d_y = $rij["y"];
                     $d_z = $rij["z"];
                 } elseif (isset($rij["system_id"])) {
                     $sys_res = mysqli_query($GLOBALS["___mysqli_ston"], "\tSELECT x, y, z\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM edtb_systems\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE id = '" . $rij["system_id"] . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 1");
                     $found = mysqli_num_rows($sys_res);
                     if ($found > 0) {
                         $sys_arr = mysqli_fetch_assoc($sys_res);
                         $d_x = $sys_arr["x"];
                         $d_y = $sys_arr["y"];
                         $d_z = $sys_arr["z"];
                     }
                 } elseif (isset($rij["system_name"]) || $found == 0) {
                     if (valid_coordinates($rij["ritem_coordx"], $rij["ritem_coordy"], $rij["ritem_coordz"])) {
                         $d_x = $rij["ritem_coordx"];
                         $d_y = $rij["ritem_coordy"];
                         $d_z = $rij["ritem_coordz"];
                     } else {
                         $sys_res = mysqli_query($GLOBALS["___mysqli_ston"], "\tSELECT x, y, z\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM edtb_systems\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE name = '" . mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $rij["system_name"]) . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 1");
                         $found = mysqli_num_rows($sys_res);
                         if ($found > 0) {
                             $sys_arr = mysqli_fetch_assoc($sys_res);
                             $d_x = $sys_arr["x"];
                             $d_y = $sys_arr["y"];
                             $d_z = $sys_arr["z"];
                         } else {
                             $sys_own_res = mysqli_query($GLOBALS["___mysqli_ston"], "\tSELECT x, y, z\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM user_systems_own\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE name = '" . mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $rij["system_name"]) . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 1");
                             $own_found = mysqli_num_rows($sys_own_res);
                             if ($own_found > 0) {
                                 $sys_own_arr = mysqli_fetch_assoc($sys_own_res);
                                 $d_x = $sys_own_arr["x"];
                                 $d_y = $sys_own_arr["y"];
                                 $d_z = $sys_own_arr["z"];
                             } else {
                                 $d_x = "";
                                 $d_y = "";
                                 $d_z = "";
                             }
                         }
                     }
                 } else {
                     $d_x = "";
                     $d_y = "";
                     $d_z = "";
                 }
             }
             $ii = 0;
             foreach ($rij as $key => $value) {
                 $field_kind = $field_type[$key];
                 $enum = false;
                 $align = "";
                 if ($field_kind == "enum('','0','1')" || $field_kind == "enum('0','1')") {
                     $align = "text-align:center;";
                     $enum = true;
                 }
                 //echo $field_kind;
                 $sort_image = '';
                 if (in_array($key, $this->fields_in_list_view)) {
                     if ($count == 1) {
                         // show nice text of a value
                         if ($this->show_text[$key]) {
                             $show_key = $this->show_text[$key];
                         } else {
                             $show_key = $key;
                         }
                         // sorting
                         if ($_GET['sort'] == $key && $_GET['ad'] == 'a') {
                             $sort_image = "<img src='/style/img/sort_a.png' style='width:9px;height:8px;border:none' alt=''>";
                             $ad = 'd';
                         }
                         if ($_GET['sort'] == $key && $_GET['ad'] == 'd') {
                             $sort_image = "<img src='/style/img/sort_d.png' style='width:9px;height:8px;border:none' alt=''>";
                             $ad = 'a';
                         }
                         // remove sort  and ad and add new ones
                         $query_sort = preg_replace('/&(sort|ad)=[^&]*/', '', $query_string) . "&sort={$key}&ad={$ad}";
                         //
                         if (isset($this->skip)) {
                             if (!in_array($key, $this->skip)) {
                                 $head .= "<td style='white-space:nowrap;padding:10px;" . $align . "'><a data-replace='true' data-target='.rightpanel' href='{$this->url_script}?{$query_sort}' class='mte_head'>{$show_key}</a> {$sort_image}</td>";
                             }
                         } else {
                             $head .= "<td style='white-space:nowrap;padding:10px;" . $align . "'><a data-replace='true' data-target='.rightpanel' href='{$this->url_script}?{$query_sort}' class='mte_head'>{$show_key}</a> {$sort_image}</td>";
                         }
                         // add distance if x,y,z are defined
                         if ($dist1 !== false) {
                             if ($_GET['sort'] == "distance" && $_GET['ad'] == 'a') {
                                 $sort_image = "<img src='/style/img/sort_a.png' style='width:9px;height:8px;border:none' alt=''>";
                                 $ad = 'd';
                             }
                             if ($_GET['sort'] == "distance" && $_GET['ad'] == 'd') {
                                 $sort_image = "<img src='/style/img/sort_d.png' style='width:9px;height:8px;border:none' alt=''>";
                                 $ad = 'a';
                             }
                             $query_sort_d = preg_replace('/&(sort|ad)=[^&]*/', '', $query_string) . "&sort=distance&ad={$ad}";
                             $head .= "<td style='white-space:nowrap;padding:10px'><a data-replace='true' data-target='.rightpanel' href='{$this->url_script}?{$query_sort_d}' class='mte_head'>Distance</a> {$sort_image}</td>";
                             $dist1 = false;
                         }
                     }
                     if ($key == $this->primary_key) {
                         if (substr($this->table, 0, 4) == "edtb") {
                             $buttons = "<td style='width:1%;white-space:nowrap;padding:10px;vertical-align:middle'></td>";
                         } else {
                             $buttons = "<td style='width:1%;white-space:nowrap;padding:10px;vertical-align:middle'><a href='javascript:void(0)' onclick='del_confirm({$value})' title='Delete {$this->show_text[$key]} {$value}'><img src='/style/img/del.png' style='width:16px;height:16px;border:none' alt=''></a>&nbsp;<a href='?{$query_string}&mte_a=edit&id={$value}' title='Edit {$this->show_text[$key]} {$value}'><img src='/style/img/edit.png' style='width:16px;height:16px;border:none' alt='Edit'></a></td>";
                         }
                         if ($key == "id" && $this->table == "edtb_systems") {
                             $this_row .= "<td style='width:1%;padding:10px;vertical-align:middle'><a href='/system.php?system_id=" . $value . "'>" . $value . "</a></td>";
                         } else {
                             $this_row .= "<td style='width:1%;padding:10px;vertical-align:middle'>{$value}</td>";
                         }
                     } else {
                         if (isset($this->skip)) {
                             if (!in_array($key, $this->skip)) {
                                 $this_row .= set_data($key, $value, $d_x, $d_y, $d_z, $dist, $this->table, $enum);
                             }
                         } else {
                             $this_row .= set_data($key, $value, $d_x, $d_y, $d_z, $dist, $this->table, $enum);
                         }
                     }
                     $ii++;
                 }
             }
             $rows .= "<tr style='border-bottom:1px solid #000;background:{$background}'>{$buttons} {$this_row}</tr>";
         }
     } else {
         $head = "<td style='padding:40px'>{$this->text['Nothing_found']}...</td>";
     }
     # navigation 3/3
     # remove start= from url
     $query_nav = preg_replace('/&(start|mte_a|id)=[^&]*/', '', $query_string);
     # this page
     $this_page = ($this->num_rows_list_view + $start) / $this->num_rows_list_view;
     # last page
     $last_page = ceil($hits_total / $this->num_rows_list_view);
     # navigatie numbers
     if ($this_page > 10) {
         $vanaf = $this_page - 10;
     } else {
         $vanaf = 1;
     }
     if ($last_page > $this_page + 10) {
         $tot = $this_page + 10;
     } else {
         $tot = $last_page;
     }
     for ($f = $vanaf; $f <= $tot; $f++) {
         $nav_toon = $this->num_rows_list_view * ($f - 1);
         if ($f == $this_page) {
             $navigation .= "<td class='mte_nav' style='color:#fffffa;background-color:#808080;font-weight:bold'>{$f}</td> ";
         } else {
             $navigation .= "<td class='mte_nav' style='background-color:#0e0e11'><a data-replace='true' data-target='.rightpanel' class='mtelink' href='{$this->url_script}?{$query_nav}&start={$nav_toon}'>{$f}</a></td>";
         }
     }
     if ($hits_total < $this->num_rows_list_view) {
         $navigation = '';
     }
     # Previous if
     if ($this_page > 1) {
         $last = ($this_page - 1) * $this->num_rows_list_view - $this->num_rows_list_view;
         $last_page_html = "<a data-replace='true' data-target='.rightpanel' href='{$this->url_script}?{$query_nav}&start={$last}' class='mte_nav_prev_next'>{$this->text['Previous']}</a>";
     }
     # Next if:
     if ($this_page != $last_page && $hits_total > 1) {
         $next = $start + $this->num_rows_list_view;
         $next_page_html = "<a data-replace='true' data-target='.rightpanel' href='{$this->url_script}?{$query_nav}&start={$next}' class='mte_nav_prev_next'>{$this->text['Next']}</a>";
     }
     $this->nav_bottom = '<span class="right" style="padding-top:6px">Number of entries: ';
     $this->nav_bottom .= number_format($hits_total);
     $this->nav_bottom .= '</span>';
     if ($navigation) {
         $nav_table = "\n\t\t\t\t<table style='border-collapse:separate;border-spacing:5px;margin-left:35%;margin-right:auto'>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td style='padding-right:6px;vertical-align:middle'>{$last_page_html}</td>\n\t\t\t\t\t\t{$navigation}\n\t\t\t\t\t\t<td style='padding-left:6px;vertical-align:middle'>{$next_page_html}</td>\n\t\t\t\t\t</tr>\n\t\t\t\t</table>\n\t\t\t";
         $this->nav_top = "\n\t\t\t\t<div style='margin-bottom:5px;margin-top:-20px;width:{$this->width_editor}'>\n\t\t\t\t\t\t{$nav_table}\n\t\t\t\t</div>\n\t\t\t";
         $this->nav_bottom .= "\n\t\t\t\t<div style='margin-top:20px;width:100%;text-align:center'>\n\t\t\t\t\t\t{$nav_table}\n\t\t\t\t</div>\n\t\t\t";
     }
     # Search form + Add Record button
     foreach ($this->fields_in_list_view as $option) {
         if ($this->show_text[$option]) {
             $show_option = $this->show_text[$option];
         } else {
             $show_option = $option;
         }
         if ($option == $in_search_field) {
             $options .= "<option selected value='{$option}'>{$show_option}</option>";
         } else {
             $options .= "<option value='{$option}'>{$show_option}</option>";
         }
     }
     $in_search_value = htmlentities(trim(stripslashes($_GET['s'])), ENT_QUOTES);
     $seach_form = "\n\t\t\t<table style='margin-left:0;padding-left:0;border-collapse:collapse;border-spacing:0'>\n\t\t\t\t<tr>\n\t\t\t\t\t<td style='white-space:nowrap;padding-bottom:20px'>\n\t\t\t\t\t\t<form method=get action='{$this->url_script}'>\n\t\t\t\t\t\t\t<input type='hidden' name='table' value='" . $_GET["table"] . "'>\n\t\t\t\t\t\t\t<select class='selectbox' name='f'>{$options}</select>\n\t\t\t\t\t\t\t<input class='textbox' type='text' name='s' value='{$in_search_value}' style='width:220px'>\n\t\t\t\t\t\t\t<input class='button' type='submit' value='{$this->text['Search']}' style='width:80px'>\n\t\t\t\t";
     if ($this->query_joomla_component) {
         $seach_form .= "<input type='hidden' value='{$this->query_joomla_component}' name='option'>";
     }
     $seach_form .= "</form>";
     if ($_GET['s'] && $_GET['f']) {
         if ($this->query_joomla_component) {
             $add_joomla = '?option=' . $this->query_joomla_component;
         }
         $seach_form .= "<button class='button' style='margin-left:0;margin-top:6px' onclick='window.location=\"{$this->url_script}{$add_joomla}\"' style='margin: 0 0 10px 10px'>{$this->text['Clear_search']}</button>";
     }
     $seach_form .= "\n\t\t\t\t\t</td>\n\n\t\t\t\t\t<td style='text-align:right;width:{$this->width_editor}'>";
     if (substr($this->table, 0, 4) != "edtb") {
         $seach_form .= "<button class='button' onclick='window.location=\"{$this->url_script}?{$query_string}&mte_a=new\"' style='margin: 0 0 10px 10px'>{$this->text['Add_Record']}</button>";
     } else {
         $seach_form .= "&nbsp;";
     }
     $seach_form .= "</td>\n\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t";
     // $this->javascript = "
     // function del_confirm(id) {
     // if (confirm('{$this->text['Delete']} record {$this->show_text[$this->primary_key]} ' + id + '...?')) {
     // window.location='$this->url_script?$query_string&mte_a=del&id=' + id
     // }
     // }
     // ";
     $this->javascript = "\n\t\t\tfunction del_confirm(id) {\n\t\t\t\tif (confirm('{$this->text['Delete']} record {$this->show_text[$this->primary_key]} ' + id + '...?')) {\n\t\t\t\t\twindow.location=window.location.href + '&mte_a=del&id=' + id\n\t\t\t\t}\n\t\t\t}\n\t\t";
     # page content
     $this->content = "\n\t\t\t<div style='width: {$this->width_editor};background:transparent;margin:0;border:none'>{$seach_form}</div>\n\t\t\t<table style='text-align:left;margin:0;border-collapse:collapse;border-spacing:0;width:{$this->width_editor}'>\n\t\t\t\t<tr style='background:#0e0e11; color: #fff'><td></td>{$head}</tr>\n\t\t\t\t{$rows}\n\t\t\t</table>\n\n\t\t\t{$this->nav_bottom}\n\t\t";
 }
示例#5
0
/**
 * Return distance from current to $system
 *
 * @param string|int $system
 * @param bool $is_id
 * @return string $distance
 * @author Mauri Kujala <*****@*****.**>
 */
function get_distance($system, $is_id = false)
{
    // fetch target coordinates
    $res = mysqli_query($GLOBALS["___mysqli_ston"], "\t(SELECT\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tedtb_systems.x AS target_x,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tedtb_systems.y AS target_y,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tedtb_systems.z AS target_z\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM edtb_systems\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE edtb_systems.name = '" . mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $system) . "')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t(SELECT\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_systems_own.x AS target_x,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_systems_own.y AS target_y,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tuser_systems_own.z AS target_z\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM user_systems_own\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE user_systems_own.name = '" . mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $system) . "')\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 1") or write_log(mysqli_error($GLOBALS["___mysqli_ston"]), __FILE__, __LINE__);
    $arr = mysqli_fetch_assoc($res);
    $target_x = $arr["target_x"];
    $target_y = $arr["target_y"];
    $target_z = $arr["target_z"];
    // figure out what coords to calculate from
    $usable_coords = usable_coords();
    $usex = $usable_coords["x"];
    $usey = $usable_coords["y"];
    $usez = $usable_coords["z"];
    $exact = $usable_coords["current"] === true ? "" : " *";
    if (valid_coordinates($target_x, $target_y, $target_z)) {
        $dist = number_format(sqrt(pow($target_x - $usex, 2) + pow($target_y - $usey, 2) + pow($target_z - $usez, 2)), 2);
        $distance = $dist . ' ly' . $exact;
    } else {
        $distance = '';
    }
    return $distance;
}
示例#6
0
文件: mte.php 项目: DBnR1/EDTB
 /**
  * Determine SQL query to use
  *
  * @return string
  */
 private function get_sql()
 {
     /**
      * select
      */
     $sql = "SELECT SQL_CACHE * FROM `{$this->table}` {$this->where_search} {$this->order_by}";
     /**
      * if sorting by distance
      */
     if ($_GET["sort"] && $_GET["sort"] == "distance") {
         if ($_GET["ad"] == "a") {
             $asc_des = "DESC";
         }
         if ($_GET["ad"] == "d") {
             $asc_des = "ASC";
         }
         // figure out what coords to calculate from
         $usable_coords = usable_coords();
         $rusex = $usable_coords["x"];
         $rusey = $usable_coords["y"];
         $rusez = $usable_coords["z"];
         $query = "SHOW COLUMNS FROM `{$this->table}`";
         $columns = $this->mysqli->query($query) or write_log($this->mysqli->error, __FILE__, __LINE__);
         while ($obj = $columns->fetch_object()) {
             $fields[] = $this->table . " . " . $obj->Field;
         }
         $columns->close();
         $fieldss = join(",", $fields);
         if ($asc_des == "DESC") {
             $this->order_by = "ORDER BY -(sqrt(pow((ritem_coordx-({$rusex})),2)+pow((ritem_coordy-({$rusey})),2)+pow((ritem_coordz-({$rusez})),2)))" . $asc_des;
         } else {
             $this->order_by = "ORDER BY sqrt(pow((ritem_coordx-({$rusex})),2)+pow((ritem_coordy-({$rusey})),2)+pow((ritem_coordz-({$rusez})),2)) DESC";
         }
         if ($this->table == "edtb_systems") {
             $sql = "SELECT " . $fieldss . ",edtb_systems.x AS ritem_coordx,\n                                                edtb_systems.y AS ritem_coordy,\n                                                edtb_systems.z AS ritem_coordz\n                                                FROM {$this->table}\n                                                {$this->order_by}";
         } elseif ($this->table == "edtb_stations") {
             $sql = "SELECT " . $fieldss . ",edtb_systems.x AS ritem_coordx,\n                                                edtb_systems.y AS ritem_coordy,\n                                                edtb_systems.z AS ritem_coordz\n                                                FROM {$this->table}\n                                                LEFT JOIN edtb_systems ON {$this->table}.system_id = edtb_systems.id\n                                                {$this->order_by}";
         } else {
             $sql = "SELECT " . $fieldss . ",IFNULL(edtb_systems.x, user_systems_own.x) AS ritem_coordx,\n                                                IFNULL(edtb_systems.y, user_systems_own.y) AS ritem_coordy,\n                                                IFNULL(edtb_systems.z, user_systems_own.z) AS ritem_coordz\n                                                FROM {$this->table}\n                                                LEFT JOIN edtb_systems ON {$this->table}.system_name = edtb_systems.name\n                                                LEFT JOIN user_systems_own ON {$this->table}.system_name = user_systems_own.name\n                                                {$this->order_by}";
         }
     }
     return $sql;
 }