1: <?php
2: 3: 4: 5:
6:
7: if (!defined('XOOPS_ROOT_PATH')) exit();
8:
9: require_once XOOPS_MODULE_PATH . "/profile/class/AbstractListAction.class.php";
10:
11: class Profile_Admin_DataDownloadAction extends Profile_AbstractListAction
12: {
13: function &_getHandler()
14: {
15: $handler =& xoops_getmodulehandler('data');
16: return $handler;
17: }
18:
19: function _getBaseUrl()
20: {
21: return "./index.php?action=DataDownload";
22: }
23:
24: function executeViewIndex(&$render)
25: {
26: $render->setTemplateName("data_download.html");
27: $handler =& $this->_getHandler();
28: $count = $handler->getCount();
29: $render->setAttribute('profileCount', $count);
30: }
31:
32: function getDefaultView()
33: {
34: return PROFILE_FRAME_VIEW_INDEX;
35: }
36:
37:
38:
39: function execute()
40: {
41: $filename = sprintf('%s_Profile_data_List.csv', $GLOBALS['xoopsConfig']['sitename']);
42: $text = '';
43: $field_line = 'uid,';
44:
45: $handler =& $this->_getHandler();
46: $defHandler =& xoops_getmodulehandler('definitions');
47: $defArr =& $defHandler->getDefinitions(false);
48:
49: $criteria = new CriteriaElement();
50: $criteria->setSort('uid');
51: $dataArr = $handler->getObjects($criteria);
52: if (count($dataArr)==0){
53: return PROFILE_FRAME_VIEW_INDEX;
54: }
55: foreach (array_keys($defArr) as $key){
56: $field_line .= $var['label'].",";
57: }
58: $field_line .= "\n";
59:
60: foreach ($dataArr as $profile){
61: $profile_data = '';
62: foreach ($profile->gets() as $key=>$value){
63: if($defArr[$key]->get('type')=='date'){
64: $value = $value ? formatTimestamp($value, 'Y/n/j H:i') : ''; }
65: if (preg_match('/[,"\r\n]/', $value)) {
66: $value = preg_replace('/"/', "\"\"", $value);
67: $value = "\"$value\"";
68: }
69: $profile_data .= $value . ',';
70: }
71: $text .= trim($profile_data, ',')."\n";
72: }
73: $text = $field_line.$text;
74:
75:
76: if (strncasecmp($GLOBALS['xoopsConfig']['language'], 'ja', 2)===0){
77: mb_convert_variables('SJIS', _CHARSET, $text);
78: }
79:
80: if( preg_match('/firefox/i' , xoops_getenv('HTTP_USER_AGENT')) ){
81: header("Content-Type: application/x-csv");
82: }else{
83: header("Content-Type: application/vnd.ms-excel");
84: }
85:
86:
87: header("Content-Disposition: attachment ; filename=\"{$filename}\"") ;
88: exit($text);
89: }
90: }
91:
92: ?>
93: