function plg_set_user_building($data, $planet_id, $planet_name, $fields, $coordinates, $temperature=null, $satellite=null) { global $db, $user_data, $pub_view; require_once("parameters/lang_empire.php"); // Verification infos $planet_name = trim($planet_name); if (!check_var($planet_name, "Galaxy")) $planet_name = ""; $planet_name = $planet_name != "" ? $planet_name : "Inconnu"; $fields = intval($fields); $temperature = intval($temperature); $satellite = intval($satellite); $planet_id = intval($planet_id); if (($pub_view == "planets" && ($planet_id < 1 || $planet_id > 9)) || ($pub_view == "lunes" && ($planet_id < 10 || $planet_id > 18))) { SendHttpStatusCode("742"); } $buildings = array("M" => 0, "C" => 0, "D" => 0, "CES" => 0, "CEF" => 0, "UdR" => 0, "UdN" => 0, "CSp" => 0, "HM" => 0, "HC" => 0, "HD" => 0, "Lab" => 0, "Ter" => 0, "Silo" => 0, "BaLu" => 0, "Pha" => 0, "PoSa" => 0); $link_building = array( $lang_building["M"] => "M", $lang_building["C"] => "C", $lang_building["D"] => "D", $lang_building["CES"] => "CES", $lang_building["CEF"] => "CEF", $lang_building["UdR"] => "UdR", $lang_building["UdN"] => "UdN", $lang_building["CSp"] => "CSp", $lang_building["HM"] => "HM", $lang_building["HC"] => "HC", $lang_building["HD"] => "HD", $lang_building["Lab"] => "Lab", $lang_building["Ter"] => "Ter", $lang_building["Silo"] => "Silo", $lang_building["BaLu"] => "BaLu", $lang_building["Pha"] => "Pha", $lang_building["PoSa"] => "PoSa"); $search = array(); $replaces = array(); $matches = array(); $OK = false; foreach ($link_building as $name => $code) { $search[] = $name; $replaces = '|'.$code; } $data = str_replace($search, $replaces, $data); preg_match_all('!\|([a-z]{1,4}) \(Niveau ([0-9]{1,3}) \)!Usi', $data, $matches); foreach ($matches[1] as $key => $value) { $buildings[$value] = (int)$matches[2][$key]; } if ($fields != null) { $insfield_name = ", `fields` "; $insfield_value = $fields.","; $updfield = ", `fields` = ".$fields; } else { $insfield_name = ""; $insfield_value = ""; $updfield = ""; } if ($temperature!=null) { $instemperature_name = ", `temperature` "; $instemperature_value = $temperature.","; $updtemperature = ", `temperature` = ".$temperature; } else { $instemperature_name = ""; $instemperature_value = ""; $updtemperature = ""; } if ($satellite!=null) { $inssatellite_name = ", `Sat` "; $inssatellite_value = $satellite.","; $updsatellite = ", `Sat` = ".$satellite; } else { $inssatellite_name = ""; $inssatellite_value = ""; $updsatellite = ""; } if ($OK) { $request = "DELETE FROM ".TABLE_USER_BUILDING." WHERE user_id = ".$user_data["user_id"]." AND planet_id= ".$planet_id; $db->sql_query($request); $request = "INSERT INTO ".TABLE_USER_BUILDING." (user_id, planet_id, planet_name, coordinates".$insfield_name.$instemperature_name.$inssatellite_name.", M, C, D, CES, CEF, UdR, UdN, CSP, HM, HC, HD, Lab, Ter, Silo, BaLu, Pha, PoSa)"; $request .= " VALUES (".$user_data["user_id"].", ".$planet_id.", '".mysql_real_escape_string($planet_name)."', '".$coordinates."',".$insfield_value.$instemperature_value.$inssatellite_value.$buildings["M"].", ".$buildings["C"].",".$buildings["D"].", ".$buildings["CES"].", ".$buildings["CEF"].", ".$buildings["UdR"].", ".$buildings["UdN"].", ".$buildings["CSp"].", ".$buildings["HM"].", ".$buildings["HC"].", ".$buildings["HD"].", ".$buildings["Lab"].", ".$buildings["Ter"].", ".$buildings["Silo"].", ".$buildings["BaLu"].", ".$buildings["Pha"].", ".$buildings["PoSa"].")"; $res=$db->sql_query($request); } else { $request = "update ".TABLE_USER_BUILDING." set planet_name = '".mysql_real_escape_string($planet_name)."', coordinates = '".$coordinates_ok."'".$updfield.$updtemperature.$updsatellite." where user_id = ".$user_data["user_id"]." and planet_id = ".$planet_id; $res=$db->sql_query($request); } log_plugin_("user_load_buildings",$planet_name."[".$coordinates."]"); if ($res==false) return false; else return true; }