4 $db = new SQLiteDatabase("sql/imgorg.db");
7 $qry = 'select i.filename as filename, i.url as url, i.id as id from Images i';
10 for ($i = 0;$i < sizeof($tags);$i++) {
11 $qry .= ' INNER JOIN Images_Tags it'.$i.' ON i.id = it'.$i.'.image_id';
12 array_push($where,' it'.$i.'.tag_id = "'.$tags[$i].'"');
16 $qry .= ' INNER JOIN Albums a ON i.album_id = a.id';
17 array_push($where, ' a.id ="'.$album.'"');
20 $qry .= ' WHERE'.join(" AND", $where);
22 $res = $db->query($qry);
23 return $res->fetchAll();
27 function upload($data, $files){
28 $name = $files["Filedata"]["name"];
29 $db = new SQLiteDatabase("sql/imgorg.db");
30 $db->queryExec('INSERT INTO Images (filename, url) VALUES("'.$name.'","images/'.$name.'")');
31 $q = $db->query('SELECT * FROM Images WHERE filename = "'.$name.'"');
32 move_uploaded_file($files["Filedata"]["tmp_name"],"../images/".$name);
35 'data' => $files["Filedata"],
36 'res' => $q->fetchObject()
38 //'test' => $phm->getImageQuality()
42 function addToAlbum($data) {
43 $images = $data->images;
44 $album = $data->album;
45 $db = new SQLiteDatabase("sql/imgorg.db");
46 for ($i = 0;$i < sizeof($images);$i++) {
47 // $db->queryExec('INSERT INTO Albums_Images (image_id, album_id) VALUES ("'.$images[$i].'","'.$album.'")');
48 $db->queryExec('UPDATE Images SET album_id = "'.$album.'" WHERE id ="'.$images[$i].'"');
50 return array('success' => true, 'images' => $images, 'album' => $album);
53 function tagImage($data) {
54 $images = $data->images;
56 $db = new SQLiteDatabase("sql/imgorg.db");
57 // if it is a known tag the id is sent, otherwise a new string is, so we need to insert
58 if (!is_numeric($tag)) {
59 $db->queryExec('INSERT INTO Tags (text) VALUES ("'.$tag.'")');
60 $q = $db->query('SELECT id FROM Tags WHERE text = "'.$tag.'"');
61 $tag = $q->fetchObject()->id;
63 for ($i = 0;$i < sizeof($images);$i++) {
64 $db->queryExec('INSERT INTO Images_Tags (image_id, tag_id) VALUES ("'.$images[$i].'","'.$tag.'")');
66 return array('success' => true, 'images' => $images, 'tag' => $tag);
69 function rename($data) {
70 $db = new SQLiteDatabase("sql/imgorg.db");
71 $image = $data->image;
74 $urls = split('/',$url);
76 $newUrl = (join('/',$urls)).'/'.$name;
78 $db->queryExec('UPDATE Images SET url = "'.$newUrl.'", filename = "'.$name.'" WHERE id = "'.$image.'"');
79 rename('../'.$url, '../'.$newUrl);
81 return array('image' => $image, 'name' => $name, 'url' => $newUrl);
84 function remove($data) {
85 $db = new SQLiteDatabase("sql/imgorg.db");
86 $images = $data->images;
87 for ($i = 0;$i < sizeof($images);$i++) {
88 $res = $db->query('SELECT url FROM Images where id ="'.$images[$i].'"');
89 $url = $res->fetchObject()->url;
91 $db->queryExec('DELETE FROM Images WHERE id ="'.$images[$i].'"');
92 $db->queryExec('DELETE FROM Images_Tags WHERE image_id ="'.$images[$i].'"');
96 function getInfo($data) {
97 $db = new SQLiteDatabase("sql/imgorg.db");
98 $image = $data->image;
99 $q = $db->query('SELECT url FROM Images WHERE id = "'.$image.'"');
100 $path = $q->fetchObject()->url;
101 $ret = exif_read_data('../'.$path);