You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.3 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. class Albums {
  3. function loadtree(){
  4. $db = new SQLiteDatabase("sql/imgorg.db");
  5. $res = $db->query('select * from Albums');
  6. $json = array();
  7. while ($o = $res->fetchObject()) {
  8. $o->leaf = true;
  9. array_push($json,$o);
  10. }
  11. return $json;
  12. }
  13. function addOrUpdate($data){
  14. $db = new SQLiteDatabase('sql/imgorg.db');
  15. $q = $db->query('SELECT * FROM Albums where id = "'.$data->id.'"');
  16. if (sizeof($q) == 0) {
  17. $res = $db->query('INSERT INTO Albums (text) VALUES ("'.$data->text.'")');
  18. } else {
  19. $res = $db->query('UPDATE Albums SET text ="'.$data->text.'" WHERE id = "'.$data->id.'"');
  20. }
  21. return array(success => true);
  22. }
  23. function remove($data) {
  24. $db = new SQLiteDatabase('sql/imgorg.db');
  25. $q = $db->queryExec('DELETE FROM Albums where id ="'.$data->album.'"');
  26. return array(success=>true, album => $data->album);
  27. }
  28. function load($data){
  29. // use $query for type-ahead
  30. $query = $data->query;
  31. $db = new SQLiteDatabase('sql/imgorg.db');
  32. $qryStr = 'SELECT * FROM Albums';
  33. if ($query) {
  34. $qryStr .= ' where text like "'.$query.'%"';
  35. }
  36. $q = $db->query($qryStr);
  37. return $q->fetchAll();
  38. }
  39. function getAlbums($data) {
  40. $db = new SQLiteDatabase('sql/imgorg.db');
  41. $image = $data->image;
  42. $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.'"');
  43. return $q->fetchAll();
  44. }
  45. function getAllInfo($data) {
  46. $db = new SQLiteDatabase('sql/imgorg.db');
  47. $res = $db->query('select * from Albums');
  48. $json = array();
  49. while ($o = $res->fetchObject()) {
  50. $q = $db->query('SELECT * FROM Images WHERE album_id = "'.$o->id.'"');
  51. $qres = $q->fetchObject();
  52. if ($qres) {
  53. $path = $qres->url;
  54. $filename = '../'.$path;
  55. if (file_exists($filename)) {
  56. $o->exif = exif_read_data($filename);
  57. }
  58. $o->filename = $qres->filename;
  59. }
  60. $o->size = sizeof($q->fetchAll());
  61. array_push($json,$o);
  62. }
  63. return $json;
  64. }
  65. }