diff --git a/ground/classes/Model.php b/ground/classes/Model.php index 0bb0ddb..1a52090 100644 --- a/ground/classes/Model.php +++ b/ground/classes/Model.php @@ -60,7 +60,14 @@ class Model { $request = App::$DB->prepare('INSERT INTO ' . $this->_tableName_ . ' (' . implode(',', array_keys($values)) . ') values (:' . implode(', :', array_keys($values)) . ')'); - return $request->execute((array) $values); + if ( $request->execute((array) $values) ) + { + return $this->getByPK(App::$DB->lastInsertId()); + } + else + { + return false; + } } function save() diff --git a/ground/controllers/IndexController.php b/ground/controllers/IndexController.php index de8591f..e0abb1c 100644 --- a/ground/controllers/IndexController.php +++ b/ground/controllers/IndexController.php @@ -20,10 +20,4 @@ class IndexController extends Controller )); } - static function actionAddpoint() - { - $point = new Point(); - $point->add($_POST); - App::redirect('/'); - } } diff --git a/ground/controllers/JsonController.php b/ground/controllers/JsonController.php index 93c4794..a0d232e 100644 --- a/ground/controllers/JsonController.php +++ b/ground/controllers/JsonController.php @@ -60,4 +60,45 @@ class JsonController extends Controller 'data' => $categories, )); } + + /** + * Добавление точки + */ + static function actionAddPoint() + { + $errors = array(); + + if(!( isset($_POST['name']) && $_POST['name'] && strlen($_POST['name']) > 1 )) $errors[]='Неверное название точки'; + if(!( isset($_POST['img']) && $_POST['img'] && strlen($_POST['img']) > 13 )) $errors[]='Плохая ссылка на изображение'; + if(!( isset($_POST['description']) && $_POST['description'] && strlen($_POST['description']) > 25 )) $errors[]='Слишком короткое описание'; + if(!( isset($_POST['categoryId']) && $_POST['categoryId'] )) $errors[]='Не задана категория точки'; + if(!( isset($_POST['source']) )) $errors[]='Не передано поле источкика информации. Допускается пустое значение.'; + if(!( isset($_POST['lat']) && $_POST['lat'] )) $errors[]='Ошибочное значение широты'; + if(!( isset($_POST['lng']) && $_POST['lng'] )) $errors[]='Ошибочное значение долготы'; + + if (empty($errors)) + { + $point = new Point(); + $point->add($_POST); + + if ( $point->id ) + { + self::renderPartial('json.php', array( + 'data' => $point->id + )); + } + else + { + header("HTTP/1.0 500 Internal Server Error"); + die('Error 500 - Internal Server Error'); + } + + } + else + { + header("HTTP/1.0 400 Bad Request"); + header('Content-Type: application/json'); + print json_encode($errors); + } + } } diff --git a/public/js/main.js b/public/js/main.js index 293f8b3..9f2633f 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -27,7 +27,7 @@ function init() { myMap.balloon.open(coords, { contentHeader:'Добавление точки', contentBody: - '
' + + '' + '

Название:
' + '

' + '

URL изображения:
' +