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