source: extensions/export_data/admin.php @ 27092

Revision 27092, 2.5 KB checked in by plg, 6 years ago (diff)

new plugin to export data from database in spreadsheet

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']) and 'albums' == $_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 
43  $query = '
44SELECT
45    id,
46    name,
47    permalink
48  FROM '.CATEGORIES_TABLE.'
49  ORDER BY id ASC
50;';
51  $result = pwg_query($query);
52
53  set_make_full_url();
54  while ($row = pwg_db_fetch_assoc($result))
55  {
56    fputcsv($output, array('url' => make_index_url(array('category' => $row))));
57  }
58  exit();
59}
60
61// +-----------------------------------------------------------------------+
62// | form                                                                  |
63// +-----------------------------------------------------------------------+
64
65// define template file
66$template->set_filename('export_data_content', realpath(EXPORT_DATA_PATH . 'admin.tpl'));
67
68// template vars
69$template->assign('EXPORT_DATA_ADMIN', EXPORT_DATA_ADMIN);
70
71// +-----------------------------------------------------------------------+
72// | sending html code                                                     |
73// +-----------------------------------------------------------------------+
74
75// send page content
76$template->assign_var_from_handle('ADMIN_CONTENT', 'export_data_content');
77
78?>
Note: See TracBrowser for help on using the repository browser.