1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* **************************************************************************** |
4
|
|
|
* - A Project by Developers TEAM For Xoops - ( https://xoops.org ) |
5
|
|
|
* **************************************************************************** |
6
|
|
|
* XNEWSLETTER - MODULE FOR XOOPS |
7
|
|
|
* Copyright (c) 2007 - 2012 |
8
|
|
|
* Goffy ( wedega.com ) |
9
|
|
|
* |
10
|
|
|
* You may not change or alter any portion of this comment or credits |
11
|
|
|
* of supporting developers from this source code or any supporting |
12
|
|
|
* source code which is considered copyrighted (c) material of the |
13
|
|
|
* original comment or credit authors. |
14
|
|
|
* |
15
|
|
|
* This program is distributed in the hope that it will be useful, |
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
* GNU General Public License for more details. |
19
|
|
|
* --------------------------------------------------------------------------- |
20
|
|
|
* @copyright Goffy ( wedega.com ) |
21
|
|
|
* @license GPL 2.0 |
22
|
|
|
* @package xnewsletter |
23
|
|
|
* @author Goffy ( [email protected] ) |
24
|
|
|
* |
25
|
|
|
* **************************************************************************** |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
use XoopsModules\Xnewsletter; |
29
|
|
|
|
30
|
|
|
// defined("XOOPS_ROOT_PATH") || die("XOOPS root path not defined"); |
31
|
|
|
require_once dirname(__DIR__) . '/include/common.php'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
function xnewsletter_plugin_getinfo_xoopsuser() |
37
|
|
|
{ |
38
|
|
|
global $xoopsDB; |
39
|
|
|
|
40
|
|
|
$pluginInfo = []; |
41
|
|
|
$pluginInfo['name'] = 'xoopsuser'; |
42
|
|
|
$pluginInfo['icon'] = XNEWSLETTER_URL . '/plugins/system_user.png'; |
43
|
|
|
//$pluginInfo['modulepath'] = XNEWSLETTER_ROOT_PATH . "/plugins/xoopsuser.php"; |
44
|
|
|
$pluginInfo['tables'][0] = $xoopsDB->prefix('users'); |
45
|
|
|
$pluginInfo['tables'][1] = $xoopsDB->prefix('groups_users_link'); |
46
|
|
|
$pluginInfo['descr'] = 'Import \XoopsUser'; |
47
|
|
|
$pluginInfo['hasform'] = 1; |
48
|
|
|
|
49
|
|
|
return $pluginInfo; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param $cat_id |
54
|
|
|
* @param $action_after_read |
55
|
|
|
* @param $limitCheck |
56
|
|
|
* @param $skipCatsubscrExist |
57
|
|
|
* @param $arr_groups |
58
|
|
|
* |
59
|
|
|
* @return int |
|
|
|
|
60
|
|
|
*/ |
61
|
|
|
function xnewsletter_plugin_getdata_xoopsuser( |
62
|
|
|
$cat_id, |
63
|
|
|
$action_after_read, |
64
|
|
|
$limitCheck, |
65
|
|
|
$skipCatsubscrExist, |
66
|
|
|
$arr_groups) |
67
|
|
|
{ |
68
|
|
|
global $xoopsDB; |
69
|
|
|
$helper = Xnewsletter\Helper::getInstance(); |
70
|
|
|
|
71
|
|
|
//$table_import = $xoopsDB->prefix('xnewsletter_import'); |
72
|
|
|
$import_status = 0 == $action_after_read ? true : false; |
73
|
|
|
$i = 0; |
74
|
|
|
$j = 0; |
75
|
|
|
|
76
|
|
|
$sql = "SELECT `email`, `name`,`uname` FROM {$xoopsDB->prefix('groups_users_link')}"; |
77
|
|
|
$sql .= " INNER JOIN {$xoopsDB->prefix('users')} ON {$xoopsDB->prefix('groups_users_link')}.uid = {$xoopsDB->prefix('users')}.uid"; |
78
|
|
|
$sql .= " WHERE ({$xoopsDB->prefix('groups_users_link')}.groupid IN (" . implode(',', $arr_groups) . '))'; |
79
|
|
|
$sql .= ' GROUP BY `email`, `name`, `uname`'; |
80
|
|
|
|
81
|
|
|
if (!$result_users = $xoopsDB->query($sql)) { |
82
|
|
|
die('MySQL-Error: ' . $GLOBALS['xoopsDB']->error()); |
83
|
|
|
} |
84
|
|
|
while (false !== ($lineArray = $xoopsDB->fetchBoth($result_users))) { |
85
|
|
|
++$i; |
86
|
|
|
$email = $lineArray[0]; |
87
|
|
|
$sex = ''; |
88
|
|
|
$firstname = ''; |
89
|
|
|
$lastname = ('' == $lineArray[1]) ? $lineArray[2] : $lineArray[1]; |
90
|
|
|
|
91
|
|
|
$subscr_id = xnewsletter_pluginCheckEmail($email); |
92
|
|
|
$catsubscr_id = xnewsletter_pluginCheckCatSubscr($subscr_id, $cat_id); |
93
|
|
|
|
94
|
|
|
if (1 == $skipCatsubscrExist && $catsubscr_id > 0) { |
95
|
|
|
//skip existing subscriptions |
96
|
|
|
} else { |
97
|
|
|
$currcatid = $catsubscr_id > 0 ? 0 : $cat_id; |
98
|
|
|
$importObj = $helper->getHandler('Import')->create(); |
99
|
|
|
$importObj->setVar('import_email', $email); |
100
|
|
|
$importObj->setVar('import_sex', $sex); |
101
|
|
|
$importObj->setVar('import_firstname', $firstname); |
102
|
|
|
$importObj->setVar('import_lastname', $lastname); |
103
|
|
|
$importObj->setVar('import_cat_id', $currcatid); |
104
|
|
|
$importObj->setVar('import_subscr_id', $subscr_id); |
105
|
|
|
$importObj->setVar('import_catsubscr_id', $catsubscr_id); |
106
|
|
|
$importObj->setVar('import_status', $import_status); |
107
|
|
|
if (!$helper->getHandler('Import')->insert($importObj)) { |
108
|
|
|
echo $importObj->getHtmlErrors(); |
109
|
|
|
exit(); |
110
|
|
|
} |
111
|
|
|
// $sql = "INSERT INTO {$table_import} (import_email, import_sex, import_firstname, import_lastname, import_cat_id, import_subscr_id, import_catsubscr_id, import_status)"; |
112
|
|
|
// $sql .= " VALUES ('$email', '$sex', '$firstname', '$lastname', $currcatid, $subscr_id, $catsubscr_id, $import_status)"; |
113
|
|
|
// $result_insert = $xoopsDB->query($sql) or die ("MySQL-Error: " . $GLOBALS['xoopsDB']->error()); |
114
|
|
|
++$j; |
115
|
|
|
} |
116
|
|
|
++$i; |
117
|
|
|
if (100000 == $j) { |
118
|
|
|
break; |
119
|
|
|
} //maximum number of processing to avoid cache overflow |
120
|
|
|
if ($limitCheck > 0 && $j == $limitCheck) { |
121
|
|
|
$import_status = false; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $j; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param $cat_id |
130
|
|
|
* @param $action_after_read |
131
|
|
|
* @param $limitCheck |
132
|
|
|
* @param $skipCatsubscrExist |
133
|
|
|
* |
134
|
|
|
* @return XoopsThemeForm |
135
|
|
|
*/ |
136
|
|
|
function xnewsletter_plugin_getform_xoopsuser($cat_id, $action_after_read, $limitCheck, $skipCatsubscrExist) |
137
|
|
|
{ |
138
|
|
|
global $xoopsDB; |
139
|
|
|
$helper = Xnewsletter\Helper::getInstance(); |
140
|
|
|
$memberHandler = xoops_getHandler('member'); |
141
|
|
|
|
142
|
|
|
$userGroups = $memberHandler->getGroupList(); |
143
|
|
|
|
144
|
|
|
$title = _AM_XNEWSLETTER_IMPORT_XOOPSUSER; |
145
|
|
|
|
146
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
147
|
|
|
$form = new \XoopsThemeForm($title, 'form_add_xoopsuser', 'import.php', 'post', true); |
148
|
|
|
$form->setExtra('enctype="multipart/form-data"'); |
149
|
|
|
|
150
|
|
|
$form->addElement(new \XoopsFormLabel('Info', _AM_XNEWSLETTER_IMPORT_INFO)); |
151
|
|
|
|
152
|
|
|
$catCriteria = new \CriteriaCompo(); |
153
|
|
|
$catCriteria->setSort('cat_id ASC, cat_name'); |
154
|
|
|
$catCriteria->setOrder('ASC'); |
155
|
|
|
$cat_select = new \XoopsFormSelect(_AM_XNEWSLETTER_IMPORT_PRESELECT_CAT, 'cat_id', $cat_id); |
156
|
|
|
$cat_select->addOptionArray($helper->getHandler('Cat')->getList($catCriteria)); |
157
|
|
|
$form->addElement($cat_select, false); |
158
|
|
|
|
159
|
|
|
// checkboxes other groups |
160
|
|
|
$select_groups = new \XoopsFormCheckBox(_AM_XNEWSLETTER_IMPORT_XOOPSUSER_GROUPS, 'xoopsuser_group', 0); |
161
|
|
|
foreach ($userGroups as $group_id => $group_name) { |
162
|
|
|
if (XOOPS_GROUP_ANONYMOUS != $group_id) { |
163
|
|
|
$select_groups->addOption($group_id, $group_name); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
$form->addElement($select_groups, true); |
167
|
|
|
|
168
|
|
|
$form->addElement(new \XoopsFormHidden('plugin', 'xoopsuser')); |
169
|
|
|
$form->addElement(new \XoopsFormHidden('cat_id', $cat_id)); |
170
|
|
|
$form->addElement(new \XoopsFormHidden('action_after_read', $action_after_read)); |
171
|
|
|
$form->addElement(new \XoopsFormHidden('limitcheck', $limitCheck)); |
172
|
|
|
$form->addElement(new \XoopsFormHidden('skipcatsubscrexist', $skipCatsubscrExist)); |
173
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'searchdata')); |
174
|
|
|
$form->addElement(new \XoopsFormButton('', 'submit', _AM_XNEWSLETTER_IMPORT_CONTINUE, 'submit')); |
175
|
|
|
|
176
|
|
|
return $form; |
177
|
|
|
} |
178
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.