public function removeStaticRouteForUser($id, $completed = false) { if ($id == $this->getId()) { // check if international challenge $currentKommun = $this->getCurrentKommun(); $ruttObj = new Rutt($this); $rutt = $ruttObj->getRutt(); $curPos = false; $lastNonAbroad = false; foreach ($rutt as $id => $stracka) { $kommun = $stracka["Kommun"]; $thisKm = $stracka["ThisKm"]; $stracka_id = $stracka["id"]; if ($curPos === false) { // if this isn't the current kommun, and it's not abroad, we'll save it as the lastNonAbroad kommun if ($kommun->getAbroad() == "false") { $lastNonAbroad = $kommun; } } if ($id == $ruttObj->getCurrentIndex()) { // we're now at the current kommun $curPos = true; if ($kommun->getAbroad() == "false" || $thisKm > 0) { // if it's not abroad, and not just a "jump to" kommun if (!$completed) { $stracka = Stracka::loadById($stracka_id); $stracka->setStatic(0); $stracka->commit(); } continue; } } elseif (!$curPos) { // we haven't reached the current kommun yet if (!$curPos && $stracka["fastRutt"] == 1) { // this is part of the ended static route, and so it will be changed to non-static... if (!$completed) { // ...if it's not a completed static route $stracka = Stracka::loadById($stracka_id); $stracka->setStatic(0); $stracka->commit(); } } elseif ($stracka["fastRutt"] == 1 && !$completed) { // if this static route isn't completed, it's changed to non-static $stracka = Stracka::loadById($stracka_id); $stracka->setStatic(0); $stracka->commit(); } else { // this looks a bit weird, it's here for historic reasons } continue; } $kommun = $stracka["Kommun"]; $stracka = Stracka::loadById($stracka_id); $stracka->delete(); } if ($lastNonAbroad != false && $this->getCurrentKommun()->getId() != $lastNonAbroad->getId()) { $strackaObj = new Stracka($lastNonAbroad, $this); $strackaObj->setTempStatus(false); $strackaObj->commit(); } $this->setUserOnStaticRoute('false'); $this->setFastRuttId(0); $this->commit(); } }
} break; case "grupp": $grupp = Grupp::loadById($_GET["id"]); Security::demand(USER); $grupp->delete(); break; case "lag": $lag = Lag::loadById($_GET["id"]); $foretag = $lag->getForetag(); Security::demand(FORETAG, $foretag); $lag->delete(); $urlHandler->redirect("Foretag", URL_EDIT, array($foretag->getId(), 0)); break; case "stracka": $stracka = Stracka::loadById($_GET["id"]); $stracka->delete(); if (isset($_GET["ajax"])) { echo "ok"; exit; } $urlHandler->redirect("Rutt", URL_VIEW); break; case "foretag": $foretag = Foretag::loadById($_GET["id"]); Security::demand(ADMIN); $foretag->delete(); Foretag::deleteForetagsnyckelWithNoForetag(); Lag::deleteLagWithNoForetag(); $urlHandler->redirect("Foretag", URL_ADMIN_LIST); break;