-<?php\r
-class Images {\r
- function load($data){\r
- $db = new SQLiteDatabase("sql/imgorg.db");\r
- $tags = $data->tags;\r
- $album = $data->album;\r
- $qry = 'select i.filename as filename, i.url as url, i.id as id from Images i';\r
- $where = array();\r
- if ($tags) {\r
- for ($i = 0;$i < sizeof($tags);$i++) {\r
- $qry .= ' INNER JOIN Images_Tags it'.$i.' ON i.id = it'.$i.'.image_id';\r
- array_push($where,' it'.$i.'.tag_id = "'.$tags[$i].'"');\r
- }\r
- }\r
- if ($album) {\r
- $qry .= ' INNER JOIN Albums a ON i.album_id = a.id';\r
- array_push($where, ' a.id ="'.$album.'"');\r
- }\r
- if ($where) {\r
- $qry .= ' WHERE'.join(" AND", $where);\r
- }\r
- $res = $db->query($qry);\r
- return $res->fetchAll();\r
-// return $qry;\r
- }\r
-\r
- function upload($data, $files){\r
- $name = $files["Filedata"]["name"];\r
- $db = new SQLiteDatabase("sql/imgorg.db");\r
- $db->queryExec('INSERT INTO Images (filename, url) VALUES("'.$name.'","images/'.$name.'")');\r
- $q = $db->query('SELECT * FROM Images WHERE filename = "'.$name.'"');\r
- move_uploaded_file($files["Filedata"]["tmp_name"],"../images/".$name);\r
-\r
- return array(\r
- 'data' => $files["Filedata"],\r
- 'res' => $q->fetchObject()\r
- //,\r
- //'test' => $phm->getImageQuality()\r
- );\r
- }\r
-\r
- function addToAlbum($data) {\r
- $images = $data->images;\r
- $album = $data->album;\r
- $db = new SQLiteDatabase("sql/imgorg.db");\r
- for ($i = 0;$i < sizeof($images);$i++) {\r
-// $db->queryExec('INSERT INTO Albums_Images (image_id, album_id) VALUES ("'.$images[$i].'","'.$album.'")');\r
- $db->queryExec('UPDATE Images SET album_id = "'.$album.'" WHERE id ="'.$images[$i].'"');\r
- }\r
- return array('success' => true, 'images' => $images, 'album' => $album);\r
- }\r
-\r
- function tagImage($data) {\r
- $images = $data->images;\r
- $tag = $data->tag;\r
- $db = new SQLiteDatabase("sql/imgorg.db");\r
- // if it is a known tag the id is sent, otherwise a new string is, so we need to insert\r
- if (!is_numeric($tag)) {\r
- $db->queryExec('INSERT INTO Tags (text) VALUES ("'.$tag.'")');\r
- $q = $db->query('SELECT id FROM Tags WHERE text = "'.$tag.'"');\r
- $tag = $q->fetchObject()->id;\r
- }\r
- for ($i = 0;$i < sizeof($images);$i++) {\r
- $db->queryExec('INSERT INTO Images_Tags (image_id, tag_id) VALUES ("'.$images[$i].'","'.$tag.'")');\r
- }\r
- return array('success' => true, 'images' => $images, 'tag' => $tag);\r
- }\r
-\r
- function rename($data) {\r
- $db = new SQLiteDatabase("sql/imgorg.db");\r
- $image = $data->image;\r
- $name = $data->name;\r
- $url = $data->url;\r
- $urls = split('/',$url);\r
- array_pop($urls);\r
- $newUrl = (join('/',$urls)).'/'.$name;\r
-\r
- $db->queryExec('UPDATE Images SET url = "'.$newUrl.'", filename = "'.$name.'" WHERE id = "'.$image.'"');\r
- rename('../'.$url, '../'.$newUrl);\r
-\r
- return array('image' => $image, 'name' => $name, 'url' => $newUrl);\r
- }\r
-\r
- function remove($data) {\r
- $db = new SQLiteDatabase("sql/imgorg.db");\r
- $images = $data->images;\r
- for ($i = 0;$i < sizeof($images);$i++) {\r
- $res = $db->query('SELECT url FROM Images where id ="'.$images[$i].'"');\r
- $url = $res->fetchObject()->url;\r
- unlink('../'.$url);\r
- $db->queryExec('DELETE FROM Images WHERE id ="'.$images[$i].'"');\r
- $db->queryExec('DELETE FROM Images_Tags WHERE image_id ="'.$images[$i].'"');\r
- }\r
- }\r
-\r
- function getInfo($data) {\r
- $db = new SQLiteDatabase("sql/imgorg.db");\r
- $image = $data->image;\r
- $q = $db->query('SELECT url FROM Images WHERE id = "'.$image.'"');\r
- $path = $q->fetchObject()->url;\r
- $ret = exif_read_data('../'.$path);\r
- return $ret;\r
- }\r
-}\r
+<?php
+class Images {
+ function load($data){
+ $db = new SQLiteDatabase("sql/imgorg.db");
+ $tags = $data->tags;
+ $album = $data->album;
+ $qry = 'select i.filename as filename, i.url as url, i.id as id from Images i';
+ $where = array();
+ if ($tags) {
+ for ($i = 0;$i < sizeof($tags);$i++) {
+ $qry .= ' INNER JOIN Images_Tags it'.$i.' ON i.id = it'.$i.'.image_id';
+ array_push($where,' it'.$i.'.tag_id = "'.$tags[$i].'"');
+ }
+ }
+ if ($album) {
+ $qry .= ' INNER JOIN Albums a ON i.album_id = a.id';
+ array_push($where, ' a.id ="'.$album.'"');
+ }
+ if ($where) {
+ $qry .= ' WHERE'.join(" AND", $where);
+ }
+ $res = $db->query($qry);
+ return $res->fetchAll();
+// return $qry;
+ }
+
+ function upload($data, $files){
+ $name = $files["Filedata"]["name"];
+ $db = new SQLiteDatabase("sql/imgorg.db");
+ $db->queryExec('INSERT INTO Images (filename, url) VALUES("'.$name.'","images/'.$name.'")');
+ $q = $db->query('SELECT * FROM Images WHERE filename = "'.$name.'"');
+ move_uploaded_file($files["Filedata"]["tmp_name"],"../images/".$name);
+
+ return array(
+ 'data' => $files["Filedata"],
+ 'res' => $q->fetchObject()
+ //,
+ //'test' => $phm->getImageQuality()
+ );
+ }
+
+ function addToAlbum($data) {
+ $images = $data->images;
+ $album = $data->album;
+ $db = new SQLiteDatabase("sql/imgorg.db");
+ for ($i = 0;$i < sizeof($images);$i++) {
+// $db->queryExec('INSERT INTO Albums_Images (image_id, album_id) VALUES ("'.$images[$i].'","'.$album.'")');
+ $db->queryExec('UPDATE Images SET album_id = "'.$album.'" WHERE id ="'.$images[$i].'"');
+ }
+ return array('success' => true, 'images' => $images, 'album' => $album);
+ }
+
+ function tagImage($data) {
+ $images = $data->images;
+ $tag = $data->tag;
+ $db = new SQLiteDatabase("sql/imgorg.db");
+ // if it is a known tag the id is sent, otherwise a new string is, so we need to insert
+ if (!is_numeric($tag)) {
+ $db->queryExec('INSERT INTO Tags (text) VALUES ("'.$tag.'")');
+ $q = $db->query('SELECT id FROM Tags WHERE text = "'.$tag.'"');
+ $tag = $q->fetchObject()->id;
+ }
+ for ($i = 0;$i < sizeof($images);$i++) {
+ $db->queryExec('INSERT INTO Images_Tags (image_id, tag_id) VALUES ("'.$images[$i].'","'.$tag.'")');
+ }
+ return array('success' => true, 'images' => $images, 'tag' => $tag);
+ }
+
+ function rename($data) {
+ $db = new SQLiteDatabase("sql/imgorg.db");
+ $image = $data->image;
+ $name = $data->name;
+ $url = $data->url;
+ $urls = split('/',$url);
+ array_pop($urls);
+ $newUrl = (join('/',$urls)).'/'.$name;
+
+ $db->queryExec('UPDATE Images SET url = "'.$newUrl.'", filename = "'.$name.'" WHERE id = "'.$image.'"');
+ rename('../'.$url, '../'.$newUrl);
+
+ return array('image' => $image, 'name' => $name, 'url' => $newUrl);
+ }
+
+ function remove($data) {
+ $db = new SQLiteDatabase("sql/imgorg.db");
+ $images = $data->images;
+ for ($i = 0;$i < sizeof($images);$i++) {
+ $res = $db->query('SELECT url FROM Images where id ="'.$images[$i].'"');
+ $url = $res->fetchObject()->url;
+ unlink('../'.$url);
+ $db->queryExec('DELETE FROM Images WHERE id ="'.$images[$i].'"');
+ $db->queryExec('DELETE FROM Images_Tags WHERE image_id ="'.$images[$i].'"');
+ }
+ }
+
+ function getInfo($data) {
+ $db = new SQLiteDatabase("sql/imgorg.db");
+ $image = $data->image;
+ $q = $db->query('SELECT url FROM Images WHERE id = "'.$image.'"');
+ $path = $q->fetchObject()->url;
+ $ret = exif_read_data('../'.$path);
+ return $ret;
+ }
+}