forked from netcommons/NetCommons2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCsvmain.class.php
More file actions
300 lines (278 loc) · 10.3 KB
/
Csvmain.class.php
File metadata and controls
300 lines (278 loc) · 10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
<?php
/**
* 会員情報>>インポート>>CSV出力用コンポーネント
*
* @package NetCommons
* @author Noriko Arai,Ryuji Masukawa
* @copyright 2006-2007 NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @project NetCommons Project, supported by National Institute of Informatics
* @access public
*/
require_once WEBAPP_DIR.'/components/csv/Main.class.php';
class User_Components_Csvmain extends Csv_Main
{
var $_db = null;
var $_session = null;
var $_container = null;
var $_usersView = null;
var $_pagesView = null;
/**
* コンストラクター
* @access public
*/
function User_Components_Csvmain() {
$this->_LE = "\n";
$this->charSet = "SJIS";
$this->mimeType = "document/unknown";
$this->division = ",";
$this->extension = ".csv";
$this->_csv = "";
$this->_container =& DIContainerFactory::getContainer();
$this->_db =& $this->_container->getComponent("DbObject");
$this->_session =& $this->_container->getComponent("Session");
$this->_usersView =& $this->_container->getComponent("usersView");
$this->_pagesView =& $this->_container->getComponent("pagesView");
}
/**
* CSVデータを追加する
* @param headers data
* @access public
*/
function add($headers, $data)
{
foreach($headers as $index) {
if (!isset($data[$index]) || ($data[$index] == "")) {
$data1[$index] = "";
continue;
}
// "\"" を追加
// $data1[$index] = preg_replace("/[\r\n]/s", " ", $data[$index]);
$data_tmp = "";
$double_qoute_flag = true;
if (strpos($data[$index], "\"") === FALSE) {
if ($data[$index] != USER_IMPORT_SPACE) {
//Excelの場合、IDという文字列はエラーとなってしまうため、小文字にする
if ($data[$index] == "ID") {
$data[$index] = "id";
}
} else {
$double_qoute_flag = false;
}
$data_tmp = $data[$index];
} else {
for ($data_idx=0; $data_idx<strlen($data[$index]); $data_idx++) {
if ($data[$index][$data_idx] == '"') {
$data_tmp = $data_tmp.'"';
}
$data_tmp = $data_tmp.$data[$index][$data_idx];
}
}
if($double_qoute_flag)
$data_tmp = '"' .$data_tmp. '"';
$data1[$index] = $data_tmp;
}
$string = implode($this->division, $data1);
$string .= "\n";
$this->_csv .= mb_convert_encoding($string, $this->charSet, "auto");
}
/**
* 会員情報のヘッダ(設定値名称)取得
* @param
* @return header_name
* @access public
*/
function make_header()
{
$header_name = null;
/* DBからヘッダを取得 */
$users_admin = $this->_usersView->getUsers(array("user_authority_id" => _AUTH_ADMIN));
if (isset($users_admin) && is_array($users_admin)) {
$items = $this->_usersView->getShowItems($users_admin[0]['user_id'], _AUTH_ADMIN, null);
if (isset($items) && is_array($items)) {
foreach($items as $item_list) {
foreach($item_list as $item) {
if (!(!strcmp($item['tag_name'], "insert_time") ||
!strcmp($item['tag_name'], "insert_user_name") ||
!strcmp($item['tag_name'], "update_time") ||
!strcmp($item['tag_name'], "update_user_name") ||
!strcmp($item['tag_name'], "password_regist_time") ||
!strcmp($item['tag_name'], "last_login_time") ||
!strcmp($item['tag_name'], "previous_login_time") ||
!strcmp($item['item_name'], USER_ITEM_AVATAR))) {
$tagname = $item['item_name'];
$header_name[$tagname] = $tagname;
if (!strcmp($item['allow_public_flag'], "1")) {
$tagname_public = sprintf(USER_IMPORT_PUBLIC_FLAG, $tagname);
$header_name[$tagname_public] = $tagname_public;
}
if (!strcmp($item['type'], USER_TYPE_EMAIL) || !strcmp($item['type'], USER_TYPE_MOBILE_EMAIL)) {
if (!strcmp($item['allow_email_reception_flag'], "1")) {
$tagname_receptemail = sprintf(USER_IMPORT_RECEPTION_EMAIL, $tagname);
$header_name[$tagname_receptemail] = $tagname_receptemail;
}
}
}
}
}
}
}
return $header_name;
}
/**
* 全会員情報(設定値)取得
* @param users
* @return datas
* @access public
*/
function make_data($users)
{
$datas = null;
$_system_user_id = $this->_session->getParameter("_system_user_id");
$_user_auth_id = $this->_session->getParameter("_user_auth_id");
if (isset($users) && is_array($users)) {
foreach($users as $user) {
/* 管理者は除く */
// if ($user['user_id'] != $_system_user_id) {
if ($user['user_authority_id'] < $_user_auth_id) {
$items = $this->_usersView->getShowItems($user['user_id'], $user['user_authority_id'], null);
if (isset($items) && is_array($items)) {
$useritem = $this->_usersView->getUserById($user['user_id'], array($this, "_getUsersFetchcallback"), null);
if (isset($useritem) && is_array($useritem)) {
$data = null;
/* ユーザデータ */
foreach($items as $item_list) {
foreach($item_list as $item) {
if (!(!strcmp($item['tag_name'], "insert_time") ||
!strcmp($item['tag_name'], "insert_user_name") ||
!strcmp($item['tag_name'], "update_time") ||
!strcmp($item['tag_name'], "update_user_name") ||
!strcmp($item['tag_name'], "password_regist_time") ||
!strcmp($item['tag_name'], "last_login_time") ||
!strcmp($item['tag_name'], "previous_login_time") ||
!strcmp($item['item_name'], USER_ITEM_AVATAR))) {
//mod AllCreator
if ((isset($item['tag_name']) && ($item['tag_name'] != "")) && $item['is_users_tbl_fld']!=false) {
if( isset($useritem[$item['tag_name']]) ) {
$item_content = $useritem[$item['tag_name']];
}
else {
$item_content = null;
}
} else {
$item_content = $item['content'];
}
$tagname = $item['item_name'];
$data[$tagname] = $this->getChangeVal($item, $item_content);
if (!strcmp($item['allow_public_flag'], "1")) {
$tagname_public = sprintf(USER_IMPORT_PUBLIC_FLAG, $tagname);
$data[$tagname_public] = $item['public_flag'];
if (!isset($data[$tagname_public]) || ($data[$tagname_public] == ""))
$data[$tagname_public] = sprintf("%s", USER_PUBLIC);
}
if (!strcmp($item['type'], USER_TYPE_EMAIL) || !strcmp($item['type'], USER_TYPE_MOBILE_EMAIL)) {
if (!strcmp($item['allow_email_reception_flag'], "1")) {
$tagname_receptemail = sprintf(USER_IMPORT_RECEPTION_EMAIL, $tagname);
$data[$tagname_receptemail] = $item['email_reception_flag'];
if (!isset($data[$tagname_receptemail]) || ($data[$tagname_receptemail] == ""))
$data[$tagname_receptemail] = sprintf("%s", _OFF);
}
}
if (!strcmp($item['tag_name'], "password")) {
$data[$tagname] = USER_IMPORT_SPACE;
// $data[$tagname] = $useritem['login_id'];
}
}
}
}
$datas[] = $data;
}
}
}
}
}
return $datas;
}
/**
* fetch時コールバックメソッド
* @param result adodb object
* @return array users
* @access private
*/
function &_getUsersFetchcallback($result) {
$container =& DIContainerFactory::getContainer();
$commonMain =& $container->getComponent("commonMain");
$timezoneMain =& $commonMain->registerClass(WEBAPP_DIR.'/components/timezone/Main.class.php', "Timezone_Main", "timezoneMain");
$languagesView =& $commonMain->registerClass(WEBAPP_DIR.'/components/languages/View.class.php', "Languages_View", "languagesView");
$languages =& $languagesView->getLanguagesList();
$ret = array();
while ($row = $result->fetchRow()) {
if(defined("_TZ_GMT0")) {
//timezone.iniがincludeされているならば
$row['timezone_offset_lang'] = $timezoneMain->getLangTimeZone($row['timezone_offset'], false);
// $row['timezone_offset_lang'] = $row['timezone_offset'];
}
if($row['authority_system_flag'] == _ON && defined($row['role_authority_name'])) {
$row['role_authority_name'] = constant($row['role_authority_name']);
}
if($row['active_flag'] == _USER_ACTIVE_FLAG_PENDING) {
$row['active_flag_lang'] = USER_ITEM_ACTIVE_FLAG_PENDING;
} else if($row['active_flag'] == _USER_ACTIVE_FLAG_MAILED) {
$row['active_flag_lang'] = USER_ITEM_ACTIVE_FLAG_MAILED;
} else if($row['active_flag'] == _USER_ACTIVE_FLAG_ON) {
$row['active_flag_lang'] = USER_ITEM_ACTIVE_FLAG_ON;
} else {
$row['active_flag_lang'] = USER_ITEM_ACTIVE_FLAG_OFF;
$row['active_flag_lang'] = USER_ITEM_ACTIVE_FLAG_OFF;
}
// $row['active_flag_lang'] = $row['active_flag'];
// 言語
if(isset($languages[$row['lang_dirname']])) {
$row['lang_dirname_lang'] = $languages[$row['lang_dirname']];
// $row['lang_dirname_lang'] = $row['lang_dirname'];
}
$ret[] = $row;
}
return $ret;
}
/**
* 設定値を名称から数値に変更
* @param item name
* @return res
* @access private
*/
function getChangeVal($item, $name)
{
if (!isset($name)) {
$name = "";
}
$res = $name;
if ($res != "") {
if (isset($item['set_options']) && is_array($item['set_options'])) {
$options = $item['set_options'];
if (!strcmp($item["type"], USER_TYPE_CHECKBOX)) {
$in_option_items = explode(",", $name);
foreach($in_option_items as $in_option_item) {
foreach ($options as $option) {
if (!strcmp($option['options'], $in_option_item)) {
$out_option_items[] = $option['def_options'];
break;
}
}
}
$res = implode("|", $out_option_items);
} else {
foreach ($options as $option) {
if (!strcmp($option['options'], $name)) {
$res = $option['def_options'];
break;
}
}
}
}
}
if ($res == "") $res = USER_IMPORT_SPACE; // 無指定
return $res;
}
}
?>