--- /dev/null
+<?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