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