[27092] | 1 | <?php |
---|
| 2 | if (!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 | |
---|
| 11 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 12 | |
---|
| 13 | load_language('plugin.lang', EXPORT_DATA_PATH); |
---|
| 14 | |
---|
| 15 | // +-----------------------------------------------------------------------+ |
---|
| 16 | // | Tabs | |
---|
| 17 | // +-----------------------------------------------------------------------+ |
---|
| 18 | |
---|
| 19 | $page['tab'] = 'home'; |
---|
| 20 | |
---|
| 21 | // tabsheet |
---|
| 22 | include_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 | |
---|
| 34 | if (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 = ' |
---|
| 44 | SELECT |
---|
| 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 | ?> |
---|