XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
UserDataDownloadAction.class.php
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12require_once XOOPS_MODULE_PATH . '/user/class/AbstractListAction.class.php';
13
14class User_UserDataDownloadAction extends User_Action
15{
16 public function &_getHandler()
17 {
18 $handler =& xoops_getmodulehandler('users');
19 return $handler;
20 }
21
22 public function _getBaseUrl()
23 {
24 return './index.php?action=UserDataDownload';
25 }
26
27 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
28 {
29 $render->setTemplateName('user_data_download.html');
30 $member_handler =& xoops_gethandler('member');
31 $user_count = $member_handler->getUserCount();
32 $render->setAttribute('user_count', $user_count);
33 }
34
35 public function getDefaultView(&$controller, &$xoopsUser)
36 {
37 return USER_FRAME_VIEW_INDEX;
38 }
39
40
42 public function execute(&$controller, &$xoopsUser)
43 {
44 $filename = sprintf('%s_User_data_List.csv', $GLOBALS['xoopsConfig']['sitename']);
45 $text = '';
46 $field_line = '';
47
48 $user_handler =& $this->_getHandler();
49 $criteria = new CriteriaElement();
50 $criteria->setSort('uid');
51 $users = $user_handler->getObjects($criteria);
52 if (!$users || 0 == (is_countable($users) ? count($users) : 0)) {
53 return USER_FRAME_VIEW_INDEX;
54 }
55 foreach ($users[0]->gets() as $key=>$var) {
56 $_f = '_MD_USER_LANG_'.strtoupper($key);
57 $field_line .= (defined($_f) ? constant($_f) : $key) . ',';
58 }
59 $field_line .= "\n";
60
61 foreach ($users as $u) {
62 $user_data = '';
63 foreach ($u->gets() as $key=>$value) {
64 switch ($key) {
65 case 'user_regdate':
66 case 'last_login':
67 $value = $value ? formatTimestamp($value, 'Y/n/j H:i') : '';
68 break;
69 default:
70 }
71 if (preg_match('/[,"\r\n]/', $value)) {
72 $value = preg_replace('/"/', '""', $value);
73 $value = "\"$value\"";
74 }
75 $user_data .= $value . ',';
76 }
77 $text .= trim($user_data, ',')."\n";
78 }
79 $text = $field_line.$text;
80
82 if (0 === strncasecmp($GLOBALS['xoopsConfig']['language'], 'ja', 2)) {
83 if (_CHARSET !== 'UTF-8') {
84 mb_convert_variables('UTF-8', _CHARSET, $text);
85 }
86 $text = pack('C*', 0xEF, 0xBB, 0xBF) . $text;
87 }
88
89 if (preg_match('/firefox/i', xoops_getenv('HTTP_USER_AGENT'))) {
90 header('Content-Type: application/x-csv');
91 } else {
92 header('Content-Type: application/vnd.ms-excel');
93 }
94
95
96 header("Content-Disposition: attachment ; filename=\"{$filename}\"") ;
97 exit($text);
98 }
99}
execute(&$controller, &$xoopsUser)
export CSV file