source: extensions/export_data/admin.php @ 28566

Last change on this file since 28566 was 28109, checked in by rvelices, 10 years ago

export_data BOM for excel

File size: 3.3 KB
Line 
1<?php
2if (!defined("PHPWG_ROOT_PATH"))
3{
4  die ("Hacking attempt!");
5}
6
7// +-----------------------------------------------------------------------+
8// | Check Access and exit when user status is not ok                      |
9// +-----------------------------------------------------------------------+
10
11check_status(ACCESS_ADMINISTRATOR);
12
13load_language('plugin.lang', EXPORT_DATA_PATH);
14
15// +-----------------------------------------------------------------------+
16// | Tabs                                                                  |
17// +-----------------------------------------------------------------------+
18
19$page['tab'] = 'home';
20
21// tabsheet
22include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
23$tabsheet = new tabsheet();
24$tabsheet->set_id('export_data');
25
26$tabsheet->add('home', l10n('Export Data'), EXPORT_DATA_ADMIN);
27$tabsheet->select($page['tab']);
28$tabsheet->assign();
29
30// +-----------------------------------------------------------------------+
31// | Actions                                                               |
32// +-----------------------------------------------------------------------+
33
34if (isset($_GET['type']))
35{
36  // output headers so that the file is downloaded rather than displayed
37  header('Content-Type: text/csv; charset=utf-8');
38  header('Content-Disposition: attachment; filename=piwigo-albums.csv');
39 
40  // create a file pointer connected to the output stream
41  $output = fopen('php://output', 'w');
42  fprintf($output, chr(0xEF).chr(0xBB).chr(0xBF));
43  if ('albums' == $_GET['type'])
44  {
45    $query = '
46SELECT
47    id,
48    name,
49    permalink
50  FROM '.CATEGORIES_TABLE.'
51  ORDER BY id ASC
52;';
53    $result = pwg_query($query);
54
55    set_make_full_url();
56    while ($row = pwg_db_fetch_assoc($result))
57    {
58      fputcsv($output, array('url' => make_index_url(array('category' => $row))));
59    }
60  }
61
62  if ('photos' == $_GET['type'])
63  {
64    $query = '
65SELECT
66    i.id,
67    file,
68    date_available,
69    date_creation,
70    i.name AS title,
71    author,
72    hit,
73    filesize,
74    width,
75    height,
76    latitude,
77    longitude,
78    group_concat(t.name) AS tags,
79    comment AS description
80  FROM '.IMAGES_TABLE.' AS i
81    LEFT JOIN '.IMAGE_TAG_TABLE.' ON image_id=i.id
82    LEFT JOIN '.TAGS_TABLE.' AS t ON tag_id=t.id
83  GROUP BY i.id
84  ORDER BY i.id
85;';
86    $result = pwg_query($query);
87
88    $is_first = true;
89    while ($row = pwg_db_fetch_assoc($result))
90    {
91      if ($is_first)
92      {
93        fputcsv($output, array_keys($row));
94        $is_first = false;
95      }
96     
97      fputcsv($output, $row);
98    }
99  }
100 
101  exit();
102}
103
104// +-----------------------------------------------------------------------+
105// | form                                                                  |
106// +-----------------------------------------------------------------------+
107
108// define template file
109$template->set_filename('export_data_content', realpath(EXPORT_DATA_PATH . 'admin.tpl'));
110
111// template vars
112$template->assign('EXPORT_DATA_ADMIN', EXPORT_DATA_ADMIN);
113
114// +-----------------------------------------------------------------------+
115// | sending html code                                                     |
116// +-----------------------------------------------------------------------+
117
118// send page content
119$template->assign_var_from_handle('ADMIN_CONTENT', 'export_data_content');
120
121?>
Note: See TracBrowser for help on using the repository browser.