if (trim($v_Code) == "") {
        $fail = true;
    }
} else {
    $fail = true;
}
if (!$fail) {
    $api = new eveAPI();
    $charIds[0] = 0;
    $charNames[0] = "";
    $corpIds[0] = 0;
    $corpNames[0] = 0;
    $api->Init($key_ID, $v_Code);
    $ret = $api->getCharXML();
    if ($ret) {
        $charIds = $api->getValueArrayFromXML($ret, "characterID");
        $charNames = $api->getValueArrayFromXML($ret, "name");
        $corpIds = $api->getValueArrayFromXML($ret, "corporationID");
        $corpNames = $api->getValueArrayFromXML($ret, "corporationName");
    } else {
        $fail = true;
    }
    if (!$fail) {
        if (IsProduction()) {
            mysql_select_db("eve.tdsin");
        } else {
            mysql_select_db("naed_Sapphire");
        }
        $sql = "CALL sp_AddAPIKey(" . $key_ID . ", '" . $v_Code . "', " . $charIds[0] . ", '" . $charNames[0] . "', " . $corpIds[0] . ", '" . $corpNames[0] . "')";
        $result = mysql_query($sql, $conn) or die(mysql_error());
        Success();
    }
}
if ($keyIdYo != -1) {
    $itemIDs[0] = 0;
    $typeIDs[0] = 0;
    $locationIDs[0] = 0;
    $moonIDs[0] = 0;
    $states[0] = 0;
    $stateTimes[0] = "";
    $onlineTimes[0] = "";
    $lastUpdates[0] = "";
    $api = new eveAPI();
    $api->Init($keyIdYo, $vCode);
    $ret = $api->getTowerListXML();
    if ($ret) {
        $itemIDs = $api->getValueArrayFromXML($ret, "itemID");
        $typeIDs = $api->getValueArrayFromXML($ret, "typeID");
        $locationIDs = $api->getValueArrayFromXML($ret, "locationID");
        $moonIDs = $api->getValueArrayFromXML($ret, "moonID");
        $states = $api->getValueArrayFromXML($ret, "state");
        $stateTimes = $api->getValueArrayFromXML($ret, "stateTimestamp");
        $onlineTimes = $api->getValueArrayFromXML($ret, "onlineTimestamp");
    } else {
        $fail = true;
    }
} else {
    $fail = true;
}
if (!$fail) {
    for ($i = 0; $i < count($itemIDs); $i++) {
        $starbasePK = 0;
         }
         if ($name == "itemID") {
             $starBaseId[$starBaseCount] = $value;
             $starBaseCount++;
         }
     }
 }
 $api = new eveAPI();
 $api->Init($keyIdYo, $vCode);
 for ($i = 0; $i < $starBaseCount; $i++) {
     $types[0] = 0;
     $amounts[0] = 0;
     $detailCount = 0;
     $ret = $api->getTowerDetailXML($starBaseId[$i]);
     if ($ret) {
         $types = $api->getValueArrayFromXML($ret, "typeID");
         $amounts = $api->getValueArrayFromXML($ret, "quantity");
         $sql = "Select\n\t\t\t\t\t\tdetail_id\n\t\t\t\t\tFrom\n\t\t\t\t\t\tStarbase_Details\n\t\t\t\t\tWhere\n\t\t\t\t\t\tstarbase_id =" . $starBasePks[$i];
         $result = mysql_query($sql, $conn) or die(mysql_error());
         while ($row = mysql_fetch_assoc($result)) {
             foreach ($row as $name => $value) {
                 if ($name == "detail_id") {
                     $detailCount++;
                 }
             }
         }
         if ($detailCount == 0) {
             //Add Everything
             for ($x = 0; $x < count($types); $x++) {
                 //Add Fuel
                 $detailPk = 0;