func('communication'); $ret = array( 'total' => 0, 'success' => 0, 'failed' => 0, 'next' => -1 ); $sql = ' FROM ' . tablename('mc_members') . ' WHERE `uniacid`=:uniacid'; $pars = array(); $pars[':uniacid'] = $_W['uniacid']; if(!empty($post['group'])) { $sql .= ' AND `groupid`=:group'; $pars[':group'] = intval($post['group']); } if(!empty($post['username'])) { $sql .= ' AND `nickname` LIKE :nickname'; $pars[':nickname'] = "%{$post['username']}%"; } if($post['type'] == 'email') { $sql .= " AND `email`!=''"; $countSql = 'SELECT COUNT(*)' . $sql; $ret['total'] = pdo_fetchcolumn($countSql, $pars); $ret['total'] = intval($ret['total']); $psize = 1; $pindex = intval($post['next']); $pindex = max(1, $pindex); $start = $psize * ($pindex - 1); $sql = 'SELECT `email`' . $sql . " LIMIT {$start}, {$psize}"; $ds = pdo_fetchall($sql, $pars); if(is_array($ds)) { foreach($ds as $row) { $str_find = array('../attachment/images'); $str_replace = array($_W['siteroot'] . 'attachment/images'); $post['content'] = str_replace($str_find, $str_replace, $post['content']); $r = ihttp_email($row['email'], $post['title'], $post['content']); if(is_error($r)) { $ret['failed']++; } else { $ret['success']++; } } } if($start + $psize < $ret['total']) { $ret['next'] = $pindex + 1; } } exit(json_encode($ret)); }