diff --git a/.gitignore b/.gitignore index 4968059..a592d4b 100644 --- a/.gitignore +++ b/.gitignore @@ -23,5 +23,9 @@ public/photos/big/*.jpeg public/photos/big/*.png public/photos/big/*.gif +tracks/*.gpx +tracks/*.kml +tracks/*.kmz + logs/* .idea diff --git a/classes/Model.php b/classes/Model.php index 8796920..83250b3 100644 --- a/classes/Model.php +++ b/classes/Model.php @@ -204,30 +204,9 @@ abstract class Model * @param array $values - ассоциативный массив соо значениями. * @return object - id добавленной записи или false. */ - function add2($values) - { - $values = $this->_vals_; - unset($values[$this->_primaryKey_]); - - $q = array(); - foreach ($values as $val) { - $q[] = '?'; - } - - var_dump('INSERT INTO `' . $this->_tableName_ . '` (`' . implode('`, `', array_keys($values)) . '`) VALUES (' . implode(', ', array_values($q)) . ') '); - die; - $res = App::DB()->prepare_query('INSERT INTO `' . $this->_tableName_ . '` (`' . implode('`, `', array_keys($values)) . '`) VALUES (' . implode(', ', array_values($q)) . ') ', self::arrayWithTypes($values)); - - if ($res) { - throw new Exception('MySQL error #' . $res->errno . ' - ' . $res->error); - } - - return $this->getByPK(App::DB()->insert_id); - } - function add($values) { - $request = App::DB()->prepare('INSERT INTO ' . $this->_tableName_ . ' (' . implode(',', array_keys($values)) . ') values (:' . implode(', :', array_keys($values)) . ')'); + $request = App::DB()->prepare('INSERT INTO `' . $this->_tableName_ . '` (`' . implode('`, `', array_keys($values)) . '`) values (:' . implode(', :', array_keys($values)) . ')'); if ($request->execute((array) $values)) { return $this->getByPK(App::DB()->lastInsertId()); } else { diff --git a/controllers/IndexController.php b/controllers/IndexController.php index cd76f3b..7f745cd 100644 --- a/controllers/IndexController.php +++ b/controllers/IndexController.php @@ -5,8 +5,8 @@ class IndexController extends Controller static function actionTest() { -// $gpxObject = simplexml_load_file('/tmp/doc2.gpx'); - $gpxObject = simplexml_load_file('/tmp/doc(gpsvisualizer.com).gpx'); + $gpxObject = simplexml_load_file('/tmp/2.gpx'); +// $gpxObject = simplexml_load_file('/tmp/doc(gpsvisualizer.com).gpx'); // $gpxObject = simplexml_load_file('/tmp/1100.gpx'); $trip = array( diff --git a/controllers/TracksController.php b/controllers/TracksController.php new file mode 100644 index 0000000..c37d6fc --- /dev/null +++ b/controllers/TracksController.php @@ -0,0 +1,59 @@ +getAll(array('where' => '`owner` = :owner'), array('owner' => App::$user->id)); + + self::render('/tracks/files.php', array( + 'files' => $files, + )); + } + + function actionUploadfile() + { +//var_dump($_POST, $_FILES); + $temp = pathinfo($_FILES['file']['name']); + $filename = $_FILES['file']['name']; + $extension = strtolower($temp['extension']); + $uploaddir = App::getBasedir().'tracks/'; +// var_dump($extension);die; + if ($extension !== 'gpx') { + App::error404('Неизвестный тип'); + } + + $tmp = TrackFiles::model()->add(array( + 'owner' => App::$user->id, + 'name' => 'Трек '.date('d-m-Y H:i:s'), + 'filename' => $filename, + 'createdAt' => date('c'), + )); + + $newName = 'track'.$tmp->id . '.' . $extension; + if (move_uploaded_file($_FILES['file']['tmp_name'], $uploaddir . $newName)) { + var_dump($tmp); + } else { + App::error404(); + } + } + +} diff --git a/models/TrackFiles.php b/models/TrackFiles.php new file mode 100644 index 0000000..3cbf8e6 --- /dev/null +++ b/models/TrackFiles.php @@ -0,0 +1,17 @@ +_tableName_ = 'trackFiles'; + parent::__construct($fromArray); + } + + static function model() + { + return new self(); + } + +} diff --git a/tracks/.gitKeep b/tracks/.gitKeep new file mode 100644 index 0000000..e69de29 diff --git a/views/tracks/files.php b/views/tracks/files.php new file mode 100644 index 0000000..feca95d --- /dev/null +++ b/views/tracks/files.php @@ -0,0 +1,18 @@ +
+