127 lines
2.5 KiB
PHP
127 lines
2.5 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 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);
|
|
}
|
|
} |