function draw_jumpgate($sid)
{
    global $map_info;
    $jumpgate_pid = get_pid_of_jumpgate($sid);
    if ($jumpgate_pid) {
        echo "<g onclick=\"clickOnJumpGate(evt)\" id=\"j" . $sid . "\">\n";
        echo "<g transform=\"translate(10 -30)\">\n";
        echo "<g>\n";
        echo "<use xlink:href=\"#sJumpgate\" id=\"j" . $sid . "UseElement\" x=\"0\" y=\"0\"/>\n";
        if ($uid == get_uid_by_pid($jumpgate_pid) || is_allied($uid, get_uid_by_pid($jumpgate_pid))) {
            echo "<noPass />";
            $jumpgate_prod_id = get_jumpgate_by_pid($jumpgate_pid);
            $current_tonnage = get_jumpgate_used_tonnage($jumpgate_pid);
            if ($current_tonnage != 0) {
                $max_tonnage = get_jumpgate_max_tonnage($jumpgate_prod_id);
                $tonnage_percent = 0.3 * ($current_tonnage * 100) / $max_tonnage;
                // 0.3 weil die anzeige exakt 30 pixel groß ist
                echo "<clipPath id=\"cJumpgate" . $sid . "\">";
                echo "<rect x=\"34\" y=\"" . $tonnage_percent . "\" width=\"4\" height=\"" . (30 - $tonnage_percent) . "\"/>";
                echo "</clipPath>";
                echo "<rect x=\"35\" y=\"0\" width=\"2\" height=\"" . $tonnage_percent . "\" style=\"stroke:blue;stroke-width:0.2pt;fill:black;\"/>";
                echo "<rect clip-path=\"url(#cJumpgate" . $sid . ")\" clip-rule=\"nonzero\" x=\"35\" y=\"0\" fill=\"url(#gLRedGreen)\" width=\"2\" height=\"30\" style=\"stroke:blue;stroke-width:0.2pt;\"/>";
            } else {
                echo "<rect x=\"35\" y=\"0\" fill=\"url(#gLRedGreen)\" width=\"2\" height=\"30\" style=\"stroke:blue;stroke-width:0.2pt;\"/>";
            }
        }
        if ($map_info->has_map_anims()) {
            echo "<animateTransform attributeType=\"XML\" attributeName=\"transform\" type=\"rotate\" values=\"360;0\" dur=\"" . ($j + 2) * 100 . "\" repeatCount=\"indefinite\"/>";
        }
        echo "</g>";
        echo "</g>";
        if ($map_info->has_map_anims()) {
            echo "<animateTransform attributeType=\"XML\" attributeName=\"transform\" type=\"rotate\" values=\"0;360\" dur=\"" . ($j + 2) * 100 . "\" repeatCount=\"indefinite\"/>";
        }
        echo "</g>\n";
    }
}
function get_jumpgate($sid)
{
    global $uid;
    global $map_info;
    if (!in_array($sid, $map_info->get_possible_scan_systems()) && !in_array($sid, $map_info->get_all_fleet_scans())) {
        return false;
    }
    // BUTTON Definitionen
    $buttonShape = "button_circle_30x30_shadow";
    $system_info = $map_info->get_system($sid);
    $j_pid = get_pid_of_jumpgate($sid);
    // pid des jumpgates
    $j_uname = get_name_by_uid($j_uid);
    // name des jumpgatebesitzers
    $sth = mysql_query("select prod_id from jumpgates where pid='{$j_pid}'");
    if (!$sth || mysql_num_rows($sth) == 0) {
        return 0;
    }
    list($j_prodid) = mysql_fetch_row($sth);
    $j_prodname = get_name_by_prod_id($j_prodid);
    $j_pic = PIC_ROOT . get_pic($j_prodid);
    // Ok, Buttons kreieren und in $new_button[] speichern
    $new_button = array();
    $new_button[] = create_button($buttonShape, "button_face_info", "alert('not yet implemented')", 0, "show info");
    $new_header = create_header($j_pic, "Jumpgate in " . $system_info["name"], "", "", "");
    // Button in das Header Tag einfügen
    for ($i = 0; $i < sizeof($new_button); $i++) {
        $new_header .= $new_button[$i];
    }
    $new_header .= "</SR_HEAD>";
    echo "newItemBox\n";
    // nötig um zu ermitteln wie der inhalt behnadelt werden soll!
    echo $new_header;
}
function jump($fid, $sid)
{
    global $uid;
    $pid = get_pid_of_jumpgate($sid);
    if (!$pid) {
        echo "no";
        return 0;
    }
    $start_sid = get_sid_by_fid($fid);
    $start_pid = get_pid_of_jumpgate($start_sid);
    if (!$start_pid) {
        echo "no";
        return 0;
    }
    $sth = mysql_query("select jv.tonnage,j.used_tonnage from jumpgates as j,jumpgatevalues as jv where j.sid={$sid} and j.pid={$pid} and jv.prod_id=j.prod_id");
    if (!$sth || mysql_num_rows($sth) == 0) {
        echo "bug";
        return 0;
    }
    $targetj = mysql_fetch_array($sth);
    $sth = mysql_query("select f.fid from fleet_info as f,jumpgates as j where f.sid=j.sid and j.sid!={$sid} and j.sid={$start_sid} and f.fid={$fid}");
    if (!$sth) {
        echo "bug";
        return 0;
    }
    if (mysql_num_rows($sth) == 0) {
        echo "same";
        return 0;
    }
    $sth = mysql_query("select fi.name as fname ,fi.sid,p.name,p.typ,fi.fid,s.tonnage,f.count from fleet_info as fi,production as p,shipvalues as s left join fleet as f on fi.fid=f.fid where p.prod_id=f.prod_id and f.fid=" . $fid . " and s.prod_id=f.prod_id and s.prod_id=p.prod_id and f.fid is not null");
    if (!$sth) {
        echo "bug";
        return 0;
    }
    while ($fleet = mysql_fetch_array($sth)) {
        if (!$max_tonnage) {
            if (!$sid_fleet) {
                $sid_fleet = $fleet["sid"];
            }
            $sth1 = mysql_query("select jv.tonnage,j.used_tonnage from jumpgates as j,jumpgatevalues as jv where j.sid=" . $fleet["sid"] . " and jv.prod_id=j.prod_id");
            if (!$sth1) {
                echo "bug";
                return 0;
            }
            $home = mysql_fetch_array($sth1);
            $home_avail = $home["tonnage"] - $home["used_tonnage"];
            $target_avail = $targetj["tonnage"] - $targetj["used_tonnage"];
            if ($home_avail < $target_avail) {
                $max_tonnage = $home_avail;
            } else {
                $max_tonnage = $target_avail;
            }
        }
        $fleet_tonnage = $fleet_tonnage + $fleet["tonnage"] * $fleet["count"];
    }
    if ($fleet_tonnage > $max_tonnage) {
        echo "max_tonnage";
        return 0;
    }
    $sth = mysql_query("select j.password,p.uid from jumpgates as j,planets as p,orbital as o where p.sid=j.sid and j.sid={$sid} and o.pid=p.id and o.prod_id=j.prod_id and j.pid=p.id");
    if (!$sth) {
        echo "bug";
        return 0;
    }
    $target_pass = mysql_fetch_array($sth);
    $sth = mysql_query("select j.password,p.uid from jumpgates as j,planets as p,orbital as o where p.sid=j.sid and j.sid=" . $sid_fleet . " and o.pid=p.id and o.prod_id=j.prod_id and j.pid=p.id");
    if (!$sth) {
        echo "bug";
        return 0;
    }
    $start_pass = mysql_fetch_array($sth);
    if ($start_pass["uid"] != $uid || $target_pass["uid"] != $uid) {
        echo "not_yours";
        return 0;
    } else {
        $sth = mysql_query("update fleet_info set sid={$sid},pid=0,tsid=0,tpid=0,mission=0 where fid={$fid}");
        if (!$sth) {
            echo "bug";
            return 0;
        }
        $sth = mysql_query("update jumpgates set used_tonnage=used_tonnage+{$fleet_tonnage} where (sid={$sid}) or (sid={$start_sid})");
        echo "success";
    }
}