194 lines
4.1 KiB
PHP
194 lines
4.1 KiB
PHP
<?php
|
|
|
|
class EdittrackController extends Controller
|
|
{
|
|
|
|
function __construct()
|
|
{
|
|
if (!App::$user->id) {
|
|
App::redirect('/');
|
|
}
|
|
}
|
|
|
|
function actionTrip()
|
|
{
|
|
$id = intval(App::getParam('id'));
|
|
$trip = Trips::model()->getByPK($id);
|
|
|
|
if (empty($_POST['name']) || $trip->isEmpty() || $trip->owner != App::$user->id) {
|
|
App::error404();
|
|
}
|
|
|
|
$trip->name = trim($_POST['name']);
|
|
$trip->description = trim($_POST['description']);
|
|
$trip->status = ($_POST['isPublic'] == 'true') ? Trips::STATUS_PUBLIC : Trips::STATUS_PRIVATE;
|
|
$trip->json = '';
|
|
$trip->save();
|
|
}
|
|
|
|
function actionDeletetrip()
|
|
{
|
|
$id = intval(App::getParam('id'));
|
|
$trip = Trips::model()->getByPK($id);
|
|
|
|
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
|
App::error404();
|
|
}
|
|
|
|
$trip->delete($id);
|
|
|
|
App::redirect('/tracks/');
|
|
}
|
|
|
|
function actionTrack()
|
|
{
|
|
$id = intval(App::getParam('id'));
|
|
|
|
$track = Tracks::model()->getByPK($id);
|
|
if (empty($_POST['name']) || $track->isEmpty()) {
|
|
App::error404();
|
|
}
|
|
|
|
$trip = Trips::model()->getByPK($track->tripId);
|
|
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
|
App::error404();
|
|
}
|
|
|
|
$track->name = trim($_POST['name']);
|
|
$track->description = trim($_POST['description']);
|
|
$track->save();
|
|
|
|
$trip->json = '';
|
|
$trip->save();
|
|
}
|
|
|
|
function actionDeletetrack()
|
|
{
|
|
$id = intval(App::getParam('id'));
|
|
|
|
$track = Tracks::model()->getByPK($id);
|
|
if ($track->isEmpty()) {
|
|
App::error404();
|
|
}
|
|
|
|
$trip = Trips::model()->getByPK($track->tripId);
|
|
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
|
App::error404();
|
|
}
|
|
|
|
$track->delete($id);
|
|
|
|
$trip->json = '';
|
|
$trip->save();
|
|
|
|
App::redirect('/tracks/edit/id/'.$trip->id);
|
|
}
|
|
|
|
function actionMergetrack()
|
|
{
|
|
$id = intval(App::getParam('id'));
|
|
|
|
$track = Tracks::model()->getByPK($id);
|
|
if ($track->isEmpty()) {
|
|
App::error404();
|
|
}
|
|
|
|
$trip = Trips::model()->getByPK($track->tripId);
|
|
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
|
App::error404();
|
|
}
|
|
|
|
$takeIt = $mergetId = $merget = FALSE;
|
|
$tracks = Tracks::model()->getAll(array('where'=>'`tripId` = ?'), array($trip->id));
|
|
foreach ($tracks as $key => $value) {
|
|
if ($takeIt) {
|
|
$mergetId = $key;
|
|
$merget = $value;
|
|
break;
|
|
}
|
|
|
|
if ($key == $id) {
|
|
$takeIt = TRUE;
|
|
}
|
|
}
|
|
|
|
if (!$mergetId) {
|
|
App::error404();
|
|
}
|
|
|
|
$track->name = $track->name . '; ' . $merget->name;
|
|
$track->distance = $track->distance + $merget->distance;
|
|
if ($merget->description) {
|
|
$track->description = $track->description . '; ' . $merget->description;
|
|
}
|
|
$track->save();
|
|
|
|
App::DB()->query("UPDATE `trackPoints` SET `trackId` = $id WHERE `trackId` = $mergetId");
|
|
$track->delete($mergetId);
|
|
|
|
$trip->json = '';
|
|
$trip->save();
|
|
|
|
App::redirect('/tracks/edit/id/'.$trip->id);
|
|
}
|
|
|
|
function actionWaypoint()
|
|
{
|
|
$id = intval(App::getParam('id'));
|
|
|
|
$waypoint = WayPoints::model()->getByPK($id);
|
|
if (empty($_POST['name']) || $waypoint->isEmpty()) {
|
|
App::error404();
|
|
}
|
|
|
|
$trip = Trips::model()->getByPK($waypoint->tripId);
|
|
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
|
App::error404();
|
|
}
|
|
|
|
$waypoint->name = trim($_POST['name']);
|
|
$waypoint->description = trim($_POST['description']);
|
|
$waypoint->save();
|
|
}
|
|
|
|
function actionDeletewaypoint()
|
|
{
|
|
$id = intval(App::getParam('id'));
|
|
|
|
$waypoint = WayPoints::model()->getByPK($id);
|
|
if ($waypoint->isEmpty()) {
|
|
App::error404();
|
|
}
|
|
|
|
$trip = Trips::model()->getByPK($waypoint->tripId);
|
|
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
|
App::error404();
|
|
}
|
|
|
|
$waypoint->delete($id);
|
|
|
|
$trip->json = '';
|
|
$trip->save();
|
|
|
|
App::redirect('/tracks/edit/id/'.$trip->id);
|
|
}
|
|
|
|
function actionGettrackdetails()
|
|
{
|
|
$id = intval(App::getParam('id'));
|
|
|
|
$track = Tracks::model()->getByPK($id);
|
|
if ($track->isEmpty()) {
|
|
App::error404();
|
|
}
|
|
|
|
$trip = Trips::model()->getByPK($track->tripId);
|
|
if ($trip->isEmpty() || $trip->owner != App::$user->id) {
|
|
App::error404();
|
|
}
|
|
|
|
$trackpoints = TrackPoints::model()->getAll(array('where' => '`trackId` = '.$track->id, 'asArray' => TRUE, 'noKeys' => TRUE,));
|
|
|
|
self::renderPartial('json.php', $trackpoints);
|
|
}
|
|
} |