File: Albums.php

package info (click to toggle)
icinga-web 1.7.1%2Bdfsg2-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 83,496 kB
  • sloc: php: 252,926; xml: 142,251; sql: 8,190; sh: 1,039; makefile: 575; perl: 215; python: 194
file content (72 lines) | stat: -rw-r--r-- 2,376 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
class Albums {
    function loadtree(){
        $db = new SQLiteDatabase("sql/imgorg.db");

        $res = $db->query('select * from Albums');
        $json = array();
        while ($o = $res->fetchObject()) {
            $o->leaf = true;
            array_push($json,$o);
        }
        return $json;
    }

    function addOrUpdate($data){
        $db = new SQLiteDatabase('sql/imgorg.db');
        $q = $db->query('SELECT * FROM Albums where id = "'.$data->id.'"');
        if (sizeof($q) == 0) {
            $res = $db->query('INSERT INTO Albums (text) VALUES ("'.$data->text.'")');
        } else {
            $res = $db->query('UPDATE Albums SET text ="'.$data->text.'" WHERE id = "'.$data->id.'"');
        }
        return array(success => true);
    }

    function remove($data) {
        $db = new SQLiteDatabase('sql/imgorg.db');
        $q = $db->queryExec('DELETE FROM Albums where id ="'.$data->album.'"');
        return array(success=>true, album => $data->album);
    }

    function load($data){
        // use $query for type-ahead
        $query = $data->query;
        $db = new SQLiteDatabase('sql/imgorg.db');
        $qryStr = 'SELECT * FROM Albums';
        if ($query) {
            $qryStr .= ' where text like "'.$query.'%"';
        }
        $q = $db->query($qryStr);
        return $q->fetchAll();
    }

    function getAlbums($data) {
        $db = new SQLiteDatabase('sql/imgorg.db');
        $image = $data->image;

        $q = $db->query('SELECT a.text as text, a.id as id FROM Albums a INNER JOIN Images i ON a.id = i.album_id WHERE i.id = "'.$image.'"');
        return $q->fetchAll();
    }

    function getAllInfo($data) {
        $db = new SQLiteDatabase('sql/imgorg.db');
        $res = $db->query('select * from Albums');
        $json = array();
        while ($o = $res->fetchObject()) {
            $q = $db->query('SELECT * FROM Images WHERE album_id = "'.$o->id.'"');
            $qres = $q->fetchObject();
            if ($qres) {
                $path = $qres->url;
                $filename = '../'.$path;
                if (file_exists($filename)) {
                    $o->exif = exif_read_data($filename);
                }
                $o->filename = $qres->filename;
            }
            $o->size = sizeof($q->fetchAll());
            array_push($json,$o);
        }
        return $json;
    }
}