function deffer_add($gala, $pos, $tgala, $tpos, $fleetnum, $returntime, $orbittime, $eta = null, $nick = null) { if (!is_numeric($gala) || !is_numeric($pos) || !is_numeric($tgala) || !is_numeric($tpos) || !is_numeric($fleetnum)) { return false; } $insert = array(); $insert['gala'] = $gala; $insert['pos'] = $pos; $insert['tgala'] = $tgala; $insert['tpos'] = $tpos; $insert['status'] = 2; $insert['orbittime'] = $orbittime; $insert['returntime'] = $returntime; if ($fleetnum) { $insert['fleetnum'] = $fleetnum; $user = user_fleet_get($gala, $pos, $fleetnum); if ($user['fid']) { $insert['fid'] = $user['fid']; } } if ($nick) { scan_update_nick($gala, $pos, $nick); } if (is_numeric($eta)) { $insert['arrival'] = gnarrival($eta); } return fleetstatus_add($insert); }
function User_fleet_status() { $id = param_num("id"); if ($id) { $this->template->assign("id", $id); } else { $id = $this->userdata['uid']; } if (!($user = getUserByID($id)) || $user['aid'] != $this->userdata['aid']) { $this->_header(); } #information message, step 2 if ($_SESSION['steps']['fleetstatus']) { #unset step unset($_SESSION['steps']['fleetstatus']); $_SESSION['steps'] = $data; $this->forms['information']['url'] = $this->backtracking->backlink(); $this->forms['information']['title'] = "Flottenstatus updaten"; $this->forms['information']['message'] = "Flottenstatus aktualisiert"; $this->forms['information']['style'] = "green"; $this->show('message_information', "Flottenstatus updaten"); } $fleetnum = param_num("fleet"); $fleet = user_fleet_bynum($id, $fleetnum); if (!$fleet) { $this->_header("index.php"); } $form = new formContainer(); $form->add(new formInput("target", "Zielkoordinaten", "string", true, 10, true, "'^\\s*(\\d{1,4}):(\\d{1,2})\\s*\$'is")); $form->add(new formInput("eta", "Flugzeit (ETA)", "string", true, 10, false, "'^\\s*(?:(\\d{1,3})|(\\d{1,2}):(\\d{1,2}))\\s*\$'is")); $status_titles[] = array("title" => "Im Orbit", "value" => 0); $status_titles[] = array("title" => "Angriffsflug", "value" => 1); $status_titles[] = array("title" => "Verteidigung", "value" => 2); if (!$fleet['status']) { $status_titles[] = array("value" => 3, "title" => "Rückflug"); } else { if ($fleet['tgala'] && $fleet['tpos']) { $galastr = " von " . $fleet['tgala'] . ":" . $fleet['tpos']; } if ($fleet['status'] == 1) { $typestr = "Angriff"; } else { $typestr = "Verteidigung"; } $status_titles[] = array("title" => "Rückflug " . $typestr . $galastr, "value" => 3); } $form->add(new formSelectBox("status", "Flottenstatus", "numeric", $status_titles, false)); $orbit = new formInput("orbit", "Zeit im Orbit", "string", true, 10, false, "'^(?:(\\d+):(\\d+)|(\\d+))\$'is"); $defftype = new formSelectBox("defftype", "Verteidigung", "numeric", array(array("title" => "Galaintern (" . $this->formattime(270 * 60, true) . ")", "value" => 270), array("title" => "Allyintern (" . $this->formattime(300 * 60, true) . ")", "value" => 300), array("title" => "Meta (" . $this->formattime(330 * 60, true) . ")", "value" => 330), array("title" => "extern (" . $this->formattime(360 * 60, true) . ")", "value" => 360)), false); if ($_POST['send']) { $form->submit("status"); $data['status'] = $form->get("status"); if ($_POST['next_x']) { switch ($data['status']) { case 1: $form->add(&$orbit); $form->submit(array("target", "orbit", "eta")); $data['returntime'] = 450; break; case 2: $form->add(&$orbit); $form->add(&$defftype); $form->submit(array("target", "orbit", "defftype", "eta")); $data['returntime'] = $form->get("defftype"); break; case 3: $form->submit("eta"); } if (!$form->hasErrors()) { // save step if ($data['status'] == 3) { $eta = $form->getregex("eta"); if ($eta[1]) { $eta = $eta[1]; } else { $eta = $eta[2] * 60 + $eta[3]; } if ($eta < 0) { $eta = 0; } $data['arrival'] = gnarrival($eta); } if ($data['status'] == 1 || $data['status'] == 2) { $eta = $form->getregex("eta"); if ($eta[1]) { $eta = $eta[1]; } else { $eta = $eta[2] * 60 + $eta[3]; } $orbit = $form->getregex("orbit"); if ($orbit[1]) { $orbit = $orbit[1] * 60 + $orbit[2]; } else { $orbit = $orbit[3]; } if ($eta == 0) { $data['orbittime'] = gnticktime($orbit); $data['arrival'] = time(); } else { $data['arrival'] = gnarrival($eta); $data['orbittime'] = $orbit; } $target = $form->getRegex("target"); $data['tgala'] = $target[1]; $data['tpos'] = $target[2]; $data['return_flight'] = 0; } if ($data['status'] == 1 && $data['tgala'] && user_get_bypos($data['tgala'], $data['tpos'])) { $form->setError("target"); $form->addError("Ziel ist Metamuitglied"); } } if (!$form->hasErrors()) { $_SESSION['steps']['fleetstatus'] = 1; if ($data['status'] == 3) { $data['status'] = $fleet['status']; $data['tgala'] = $fleet['tgala']; $data['tpos'] = $fleet['tpos']; $data['return_flight'] = 1; } $data['fleetnum'] = $fleetnum; $data['gala'] = $user['gala']; $data['pos'] = $user['pos']; $data['fid'] = $fleet['fid']; if ($data['status'] || $data['return_flight']) { if ($fleet['fsid']) { fleetstatus_update($fleet['fsid'], $data); } else { #$check = fleetstatus_get_byfleetnum($user['gala'],$user['pos'],true); #if(count($check) >= 2) fleetstatus_delete($check[0]['fsid']); fleetstatus_add($data); } } else { if ($fleet['fsid']) { fleetstatus_delete($fleet['fsid']); } } $this->_header("user.php?action=fleetstatus&send"); } } else { if ($data['status'] == 1) { $form->add(&$orbit); } if ($data['status'] == 2) { $form->add(&$orbit); $form->add(&$defftype); } if ($data['status'] == 1) { if ($data['status'] == $fleet['status'] && !$fleet['return_flight']) { $form->set("orbit", $this->formattime($fleet['orbittime'] * 60)); if ($fleet['tgala']) { $form->set("target", "{$fleet['tgala']}:{$fleet['tpos']}"); } } else { $form->set("orbit", $this->formattime(75 * 60)); } } if ($data['status'] == 2) { if ($data['status'] == $fleet['status'] && !$fleet['return_flight']) { $defftype->select($fleet['returntime']); $form->set("orbit", $this->formattime($fleet['orbittime'] * 60)); if ($fleet['tgala']) { $form->set("target", $fleet['tgala'] . ":" . $fleet['tpos']); } } else { $form->set("orbit", $this->formattime(300 * 60)); $defftype->select(360); } } if (($fleet['status'] == 2 || $fleet['status'] == 1) && $data['status'] == 3 && !$fleet['return_flight']) { $eta = $fleet['arrival'] - time(); if ($eta < 0) { $eta = 0; } $form->set("eta", $this->formattime($fleet['returntime'] * 60 - $eta)); } if ($data['status'] == $fleet['status'] || $data['status'] == 3 && $fleet['return_flight']) { $form->set("eta", $this->formattime($fleet['arrival'] - time())); } } } else { if ($fleet['return_flight']) { $data['status'] = 3; } else { $data['status'] = $fleet['status']; if (($fleet['status'] == 1 || $fleet['status'] == 2) && $fleet['tgala']) { $form->set("target", $fleet['tgala'] . ":" . $fleet['tpos']); } } $form->select("status", $data['status']); #$form->set("status",$data['status']); if ($data['status'] == 1 || $data['status'] == 2) { $form->add(&$orbit); } if ($fleet['arrival']) { $eta = $fleet['arrival'] - time(); if ($eta < 0) { $eta_exact = 0; } else { $eta_exact = $eta; } $form->set("eta", $this->formattime($eta_exact)); } if ($data['status'] == 2) { if ($fleet['orbittime']) { if ($eta < 0) { $orbittime = $fleet['orbittime'] * 60 + $eta; } else { $orbittime = $fleet['orbittime'] * 60; } $form->set("orbit", $this->formattime($orbittime)); } } if ($data['status'] == 1) { #echo "eta: ".($eta/60)."<br>"; if ($fleet['orbittime']) { if ($eta < 0) { $orbittime = $fleet['orbittime'] * 60 + $eta; } else { $orbittime = $fleet['orbittime'] * 60; } $form->set("orbit", $this->formattime($orbittime)); } } if ($data['status'] == 2) { $form->add(&$defftype); $form->select("defftype", $fleet['returntime']); } } $form->registerVars(&$this->template); $this->template->assign("fleet", $fleetnum); $this->show("user_fleetstatus", "Flottenstatus updaten"); }