function PommoGroup($groupID = NULL, $status = 1, $filter = FALSE) { $this->_status = $status; if (!is_numeric($groupID)) { // exception if no group ID was passed -- group assumes "all subscribers". $GLOBALS['pommo']->requireOnce($GLOBALS['pommo']->_baseDir . 'inc/helpers/subscribers.php'); $this->_group = array('rules' => array(), 'id' => 0); $this->_id = 0; $this->_name = Pommo::_T('All Subscribers'); $this->_memberIDs = is_array($filter) ? PommoGroup::getMemberIDs($this->_group, $status, $filter) : null; $this->_tally = is_array($filter) ? count($this->_memberIDs) : PommoSubscriber::tally($status); return; } $this->_group = current(PommoGroup::get(array('id' => $groupID))); $this->_id = $groupID; $this->_name =& $this->_group['name']; $this->_memberIDs = PommoGroup::getMemberIDs($this->_group, $status, $filter); $this->_tally = count($this->_memberIDs); return; }
if ($state['order'] != 'asc' && $state['order'] != 'desc') { $state['order'] = 'asc'; } if (!is_numeric($state['sort']) && $state['sort'] != 'email' && $state['sort'] != 'ip' && $state['sort'] != 'time_registered' && $state['sort'] != 'time_touched') { $state['sort'] = 'email'; } if (!is_numeric($state['status'])) { $state['status'] = 1; } if (!is_numeric($state['group']) && $state['group'] != 'all') { $state['group'] = 'all'; } if (isset($_REQUEST['searchClear'])) { $state['search'] = false; } elseif (isset($_REQUEST['searchField']) && (is_numeric($_REQUEST['searchField']) || $_REQUEST['searchField'] == 'email' || $_REQUEST['searchField'] == 'ip' || $_REQUEST['searchField'] == 'time_registered' || $_REQUEST['searchField'] == 'time_touched')) { $_REQUEST['searchString'] = trim($_REQUEST['searchString']); $state['search'] = empty($_REQUEST['searchString']) ? false : array('field' => $_REQUEST['searchField'], 'string' => trim($_REQUEST['searchString'])); } /********************************** DISPLAY METHODS *********************************/ // Get the *empty* group [no member IDs. 3rd arg is set TRUE] $group = new PommoGroup($state['group'], $state['status'], $state['search']); // Calculate and Remember number of pages for this group/status combo $state['pages'] = is_numeric($group->_tally) && $group->_tally > 0 ? ceil($group->_tally / $state['limit']) : 0; $smarty->assign('state', $state); $smarty->assign('tally', $group->_tally); $smarty->assign('groups', PommoGroup::get()); $smarty->assign('fields', PommoField::get()); $smarty->display('admin/subscribers/subscribers_manage.tpl'); Pommo::kill();
Pommo::requireOnce($pommo->_baseDir . 'inc/classes/sql.gen.php'); Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/groups.php'); Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/fields.php'); Pommo::requireOnce($pommo->_baseDir . 'inc/helpers/rules.php'); $pommo->init(); $logger =& $pommo->_logger; $dbo =& $pommo->_dbo; /********************************** SETUP TEMPLATE, PAGE *********************************/ Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); $smarty->assign('returnStr', Pommo::_T('Groups Page')); // Initialize page state with default values overriden by those held in $_REQUEST $state =& PommoAPI::stateInit('groups_edit', array('group' => 0), $_REQUEST); $groups =& PommoGroup::get(); $fields =& PommoField::get(); $group =& $groups[$state['group']]; if (empty($group)) { Pommo::redirect('subscribers_groups.php'); } $rules = PommoSQL::sortRules($group['rules']); $rules['and'] = PommoSQL::sortLogic($rules['and']); $rules['or'] = PommoSQL::sortLogic($rules['or']); foreach ($rules as $key => $a) { if ($key == 'include' || $key == 'exclude') { foreach ($a as $k => $gid) { $rules[$key][$k] = $groups[$gid]['name']; } } }
case 'is': case 'not': case 'less': case 'greater': $values = array_unique($_REQUEST['match']); $type = $_REQUEST['type'] == 'or' ? 'or' : 'and'; PommoRules::addFieldRule($state['group'], $_REQUEST['field'], $_REQUEST['logic'], $values, $type); break; } $json->add('callbackFunction', 'redirect'); $json->add('callbackParams', $pommo->_baseUrl . 'admin/subscribers/groups_edit.php'); $json->serve(); break; case 'updateRule': Pommo::requireOnce($pommo->_baseDir . 'inc/classes/sql.gen.php'); $group =& current(PommoGroup::get(array('id' => $state['group']))); $rules = PommoSQL::sortRules($group['rules']); switch ($_REQUEST['request']) { case 'update': if ($_REQUEST['type'] == 'or' && count($rules['and']) < 2) { $json->add('callbackFunction', 'resume'); $json->success(Pommo::_T('At least 1 "and" rule must exist before an "or" rule takes effect.')); } PommoRules::changeType($group['id'], $_REQUEST['fieldID'], $_REQUEST['logic'], $_REQUEST['type']); break; case 'delete': PommoRules::deleteRule($group['id'], $_REQUEST['fieldID'], $_REQUEST['logic']); break; } $json->add('callbackFunction', 'redirect'); $json->add('callbackParams', $pommo->_baseUrl . 'admin/subscribers/groups_edit.php');
function groupSQL(&$group, $tally = false, $status = 1, $filter = false) { // used to prevent against group include/exclude recursion static $groups; if (!isset($groups[$group['id']])) { $groups[$group['id']] = TRUE; } global $pommo; $dbo =& $pommo->_dbo; /* SELECT count(subscriber_id) from subscribers where status ='1' AND ( // base group subscriber_id in (select subscriber_id from subscriber_data where field_id =3 and value IN ('on')) AND subscriber_id in (select subscriber_id from subscriber_data where field_id =4 and value NOT IN ('lemur')) OR subscriber_id in (select subscriber_id from subscriber_data where field_id =5 and value NOT IN ('on')) ) AND subscriber_ID NOT IN( // exclude group SELECT subscriber_id from subscribers where status ='1' AND ( subscriber_id in (select ... zzz) AND subsriber_id in (select ... zzz) OR subscriber_id in (select ... zzz) ) ) OR subscriber_ID IN( // include group SELECT subscriber_id from subscribers where status ='1' AND ( subscriber_id in (select ... zzz) AND subsriber_id in (select ... zzz) OR subscriber_id in (select ... zzz) ) ) */ $rules = PommoSQL::sortRules($group['rules']); $ands = PommoSQL::getSubQueries(PommoSQL::sortLogic($rules['and'])); $ors = empty($rules['or']) ? array() : PommoSQL::getSubQueries(PommoSQL::sortLogic($rules['or'])); $sql = $tally ? 'SELECT count(subscriber_id) ' : 'SELECT subscriber_id '; $sql .= "\n\t\t\tFROM {$dbo->table['subscribers']}\n\t\t\tWHERE status=" . intval($status); $q = FALSE; if (!empty($ands)) { $sql .= " AND (\n"; foreach ($ands as $k => $s) { if ($k != 0) { $sql .= "\n AND "; } $sql .= $s; } foreach ($ors as $s) { $sql .= "\n OR {$s}"; } $sql .= "\n)"; $q = TRUE; } foreach ($rules['exclude'] as $gid) { if (!isset($groups[$gid])) { $sql .= "\nAND subscriber_id NOT IN (\n"; $sql .= PommoSQL::groupSQL(current(PommoGroup::get(array('id' => $gid)))); $sql .= "\n)"; } $q = TRUE; } foreach ($rules['include'] as $gid) { if (!isset($groups[$gid])) { $sql .= "\n" . ($q ? 'OR' : 'AND') . " subscriber_id IN (\n"; $sql .= PommoSQL::groupSQL(current(PommoGroup::get(array('id' => $gid)))); $sql .= "\n)"; } $q = TRUE; } // If a filter/search is requested, perform a match if (is_array($filter) && !empty($filter['field']) && !empty($filter['string'])) { // make MySQL LIKE() compliant $filter['string'] = mysql_real_escape_string(addcslashes($filter['string'], '%_')); $sql .= is_numeric($filter['field']) ? "\n AND subscriber_id in (select subscriber_id from {$dbo->table['subscriber_data']} WHERE field_id = " . (int) $filter['field'] . " AND value LIKE '%{$filter['string']}%')" : "\n AND " . mysql_real_escape_string($filter['field']) . " LIKE '%{$filter['string']}%'"; } return $sql; }
Pommo::requireOnce($pommo->_baseDir . 'inc/classes/template.php'); $smarty = new PommoTemplate(); $smarty->prepareForForm(); // add group if requested if (!empty($_POST['group_name'])) { if (PommoGroup::nameExists($_POST['group_name'])) { $logger->addMsg(sprintf(Pommo::_T('Group name (%s) already exists'), $_POST['group_name'])); } else { $group = PommoGroup::make(array('name' => $_POST['group_name'])); $id = PommoGroup::add($group); $id ? Pommo::redirect("groups_edit.php?group={$id}") : $logger->addMsg(Pommo::_T('Error with addition.')); } } if (!empty($_GET['delete'])) { // make sure it is a valid group $group = current(PommoGroup::get(array('id' => $_GET['group_id']))); if (empty($group)) { Pommo::redirect($_SERVER['PHP_SELF']); } $affected = PommoGroup::rulesAffected($group['id']); // See if this change will affect any subscribers, if so, confirm the change. if ($affected > 1 && empty($_GET['dVal-force'])) { $smarty->assign('confirm', array('title' => Pommo::_T('Confirm Action'), 'nourl' => $_SERVER['PHP_SELF'] . '?group_id=' . $_GET['group_id'], 'yesurl' => $_SERVER['PHP_SELF'] . '?group_id=' . $_GET['group_id'] . '&delete=TRUE&dVal-force=TRUE', 'msg' => sprintf(Pommo::_T('%1$s filters belong this group . Are you sure you want to remove %2$s?'), '<b>' . $affected . '</b>', '<b>' . $group['name'] . '</b>'))); $smarty->display('admin/confirm.tpl'); Pommo::kill(); } else { // delete group if (!PommoGroup::delete($group['id'])) { $logger->addMsg(Pommo::_T('Group cannot be deleted.')); } else { $logger->addMsg(sprintf(Pommo::_T('%s deleted.'), $group['name']));