<commit_before><?php
if (!defined('PHPLISTINIT')) exit;

$filterpanel = $countpanel = $paging = '';

if (!isset ($_SESSION["userlistfilter"]) || !$_SESSION["userlistfilter"]) {
  $_SESSION["userlistfilter"] = array ();
}
if (isset ($_GET['sortby'])) {
  $sortby = removeXss($_GET['sortby']);
  ## only allow spaces and word chars
  $sortby = preg_replace('/[^\w ]+/','',$sortby);
} else {
  $sortby = '';
}

if (isset($_GET["delete"])){
   $delete = sprintf("%d", $_GET["delete"]);
}
else $delete = 0;
#print $_GET["delete"].' '.$delete .isSuperUser();exit;

if (isset($_GET["start"])){
   $start = sprintf("%d", $_GET["start"]);
}
else $start = 0;

$searchdone = 1;
if (!empty ($_GET['start'])) {
  $start = sprintf('%d', $_GET['start']);
} else {
  $start = 0;
}
$unconfirmed = !empty ($_GET['unconfirmed']) ? sprintf('%d', $_GET['unconfirmed']) : 0;
$blacklisted = !empty ($_GET['blacklisted']) ? sprintf('%d', $_GET['blacklisted']) : 0;
if (isset ($_GET['sortorder'])) {
  if ($_GET['sortorder'] == 'asc') {
    $sortorder = 'asc';
  } else {
    $sortorder = 'desc';
  }
} else {
  $sortorder = 'desc';
}
if (isset ($_GET['listid'])) {
  $listid = sprintf('%d', $_GET['listid']);
} else {
  $listid = 0;
}
if (isset ($_GET["find"])) {
  if (!isset ($_GET['findby'])) {
    $_GET['findby'] = '';
  }

  if ($_GET["find"] == "NULL") {
    $_SESSION["userlistfilter"]["find"] = "";
    $_SESSION["userlistfilter"]["findby"] = "";
  } else {
    $_SESSION["userlistfilter"]["find"] = removeXss($_GET["find"]);
    $_SESSION["userlistfilter"]["findby"] = removeXss($_GET["findby"]);
  }
} else {
  $_SESSION["userlistfilter"]["find"] = "";
  $_SESSION["userlistfilter"]["findby"] = "";
}

$find = $_SESSION["userlistfilter"]["find"];
$findby = $_SESSION["userlistfilter"]["findby"];
if (!$findby) {
  $findby = "email";
}

# hmm interesting, if they select a findby but not a find, use the Sql wildcard:
if ($findby && !$find)
  # this is very slow, so instead erase the findby.
  #  $find = '%';
  $findby = '';

$system_findby = array (
  "email",
  "foreignkey"
);

if ($findby && $find && !in_array($findby, $system_findby)) {
  $find_url = '&amp;find=' . urlencode($find) . "&amp;findby=" . urlencode($findby);
  $findatt = Sql_Fetch_Array_Query("select id,tablename,type,name from {$tables["attribute"]} where id = $findby");
  switch ($findatt["type"]) {
    case "textline" :
    case "hidden" :
      $findtables = ',' . $tables["user_attribute"];
      $findbyselect = sprintf(' %s.userid = %s.id and
              %s.attributeid = %d and %s.value like "%%%s%%"', $tables["user_attribute"], $tables["user"], $tables["user_attribute"], $findby, $tables["user_attribute"], $find);
      $findfield = $tables["user_attribute"] . ".value as display, " . $tables["user"] . ".bouncecount";
      $findfieldname = $findatt["name"];
      break;
    case "select" :
    case "radio" :
      $findtables = ',' . $tables["user_attribute"] . ',' . $table_prefix . 'listattr_' . $findatt["tablename"];
      $findbyselect = sprintf(' %s.userid = %s.id and
              %s.attributeid = %d and %s.value = %s.id and
              %s.name like "%%%s%%"', $tables["user_attribute"], $tables["user"], $tables["user_attribute"], $findby, $tables["user_attribute"], $table_prefix .
      'listattr_' . $findatt["tablename"], $table_prefix .
      'listattr_' . $findatt["tablename"], $find);
      $findfield = $table_prefix . 'listattr_' . $findatt["tablename"] . ".name as display, " . $tables["user"] . ".bouncecount";
      $findfieldname = $findatt["name"];
      break;
  }
} else {
  $findtables = '';
  $findbyselect = sprintf(' %s like "%%%s%%"', $findby, $find);
  ;
  $findfield = $tables["user"] . ".bouncecount," . $tables["user"] . ".foreignkey";
  $findfieldname = "Email";
  $find_url = '&amp;find=' . urlencode($find);
}

if ($require_login && !isSuperUser()) {
  $access = accessLevel("users");
  switch ($access) {
    case "owner" :
      $table_list = $tables["user"] . ',' . $tables["listuser"] . ',' . $tables["list"] . $findtables;
      $subselect = "{$tables["user"]}.id = {$tables["listuser"]}.userid and {$tables["listuser"]}.listid = {$tables["list"]}.id and {$tables["list"]}.owner = " . $_SESSION["logindetails"]["id"];
      if ($unconfirmed)
        $subselect .= ' and !confirmed ';
      if ($blacklisted)
        $subselect .= ' and blacklisted ';
      if ($find) {
        $listquery = "select DISTINCT {$tables["user"]}.email,{$tables["user"]}.id,$findfield,confirmed from " . $table_list . " where $subselect and $findbyselect";
        $count = Sql_query("SELECT count({$tables["user"]}.id) FROM " . $table_list . " where $subselect and $findbyselect");
        $unconfirmedcount = Sql_query("SELECT count({$tables["user"]}.id) FROM " . $table_list . " where $subselect and !confirmed and $findbyselect");
      } else {
        $listquery = "SELECT DISTINCT {$tables["user"]}.email,{$tables["user"]}.id,$findfield,confirmed FROM " . $table_list . " WHERE $subselect";
        $count = Sql_query("SELECT count({$tables["user"]}.id) FROM " . $table_list . " WHERE $subselect");
        $unconfirmedcount = Sql_query("SELECT count({$tables["user"]}.id) FROM " . $table_list . " WHERE !confirmed and $subselect");
      }
      break;
    case "all" :
    case "view" :
      $table_list = $tables["user"] . $findtables;
      if ($find) {
        if ($unconfirmed)
          $findbyselect .= ' and !confirmed ';
        if ($blacklisted)
          $findbyselect .= ' and blacklisted ';
        $listquery = "select DISTINCT {$tables["user"]}.email,{$tables["user"]}.id,$findfield,{$tables["user"]}.confirmed from " . $table_list . " where $findbyselect";
        $count = Sql_query("SELECT count(*) FROM " . $table_list . " where $findbyselect");
        $unconfirmedcount = Sql_query("SELECT count(*) FROM " . $table_list . " where !confirmed && $findbyselect");
      } else {
        $listquery = "select DISTINCT {$tables["user"]}.email,{$tables["user"]}.id,$findfield,{$tables["user"]}.confirmed from " . $table_list;
        $count = Sql_query("SELECT count(*) FROM " . $table_list);
        $unconfirmedcount = Sql_query("SELECT count(*) FROM " . $table_list . " where !confirmed");
        $searchdone = 0;
      }<commit_msg>#17218 - fix count of subscribers for sub-admins<commit_after><?php
if (!defined('PHPLISTINIT')) exit;

$filterpanel = $countpanel = $paging = '';

if (!isset ($_SESSION["userlistfilter"]) || !$_SESSION["userlistfilter"]) {
  $_SESSION["userlistfilter"] = array ();
}
if (isset ($_GET['sortby'])) {
  $sortby = removeXss($_GET['sortby']);
  ## only allow spaces and word chars
  $sortby = preg_replace('/[^\w ]+/','',$sortby);
} else {
  $sortby = '';
}

if (isset($_GET["delete"])){
   $delete = sprintf("%d", $_GET["delete"]);
}
else $delete = 0;
#print $_GET["delete"].' '.$delete .isSuperUser();exit;

if (isset($_GET["start"])){
   $start = sprintf("%d", $_GET["start"]);
}
else $start = 0;

$searchdone = 1;
if (!empty ($_GET['start'])) {
  $start = sprintf('%d', $_GET['start']);
} else {
  $start = 0;
}
$unconfirmed = !empty ($_GET['unconfirmed']) ? sprintf('%d', $_GET['unconfirmed']) : 0;
$blacklisted = !empty ($_GET['blacklisted']) ? sprintf('%d', $_GET['blacklisted']) : 0;
if (isset ($_GET['sortorder'])) {
  if ($_GET['sortorder'] == 'asc') {
    $sortorder = 'asc';
  } else {
    $sortorder = 'desc';
  }
} else {
  $sortorder = 'desc';
}
if (isset ($_GET['listid'])) {
  $listid = sprintf('%d', $_GET['listid']);
} else {
  $listid = 0;
}
if (isset ($_GET["find"])) {
  if (!isset ($_GET['findby'])) {
    $_GET['findby'] = '';
  }

  if ($_GET["find"] == "NULL") {
    $_SESSION["userlistfilter"]["find"] = "";
    $_SESSION["userlistfilter"]["findby"] = "";
  } else {
    $_SESSION["userlistfilter"]["find"] = removeXss($_GET["find"]);
    $_SESSION["userlistfilter"]["findby"] = removeXss($_GET["findby"]);
  }
} else {
  $_SESSION["userlistfilter"]["find"] = "";
  $_SESSION["userlistfilter"]["findby"] = "";
}

$find = $_SESSION["userlistfilter"]["find"];
$findby = $_SESSION["userlistfilter"]["findby"];
if (!$findby) {
  $findby = "email";
}

# hmm interesting, if they select a findby but not a find, use the Sql wildcard:
if ($findby && !$find)
  # this is very slow, so instead erase the findby.
  #  $find = '%';
  $findby = '';

$system_findby = array (
  "email",
  "foreignkey"
);

if ($findby && $find && !in_array($findby, $system_findby)) {
  $find_url = '&amp;find=' . urlencode($find) . "&amp;findby=" . urlencode($findby);
  $findatt = Sql_Fetch_Array_Query("select id,tablename,type,name from {$tables["attribute"]} where id = $findby");
  switch ($findatt["type"]) {
    case "textline" :
    case "hidden" :
      $findtables = ',' . $tables["user_attribute"];
      $findbyselect = sprintf(' %s.userid = %s.id and
              %s.attributeid = %d and %s.value like "%%%s%%"', $tables["user_attribute"], $tables["user"], $tables["user_attribute"], $findby, $tables["user_attribute"], $find);
      $findfield = $tables["user_attribute"] . ".value as display, " . $tables["user"] . ".bouncecount";
      $findfieldname = $findatt["name"];
      break;
    case "select" :
    case "radio" :
      $findtables = ',' . $tables["user_attribute"] . ',' . $table_prefix . 'listattr_' . $findatt["tablename"];
      $findbyselect = sprintf(' %s.userid = %s.id and
              %s.attributeid = %d and %s.value = %s.id and
              %s.name like "%%%s%%"', $tables["user_attribute"], $tables["user"], $tables["user_attribute"], $findby, $tables["user_attribute"], $table_prefix .
      'listattr_' . $findatt["tablename"], $table_prefix .
      'listattr_' . $findatt["tablename"], $find);
      $findfield = $table_prefix . 'listattr_' . $findatt["tablename"] . ".name as display, " . $tables["user"] . ".bouncecount";
      $findfieldname = $findatt["name"];
      break;
  }
} else {
  $findtables = '';
  $findbyselect = sprintf(' %s like "%%%s%%"', $findby, $find);
  ;
  $findfield = $tables["user"] . ".bouncecount," . $tables["user"] . ".foreignkey";
  $findfieldname = "Email";
  $find_url = '&amp;find=' . urlencode($find);
}

if ($require_login && !isSuperUser()) {
  $access = accessLevel("users");
  switch ($access) {
    case "owner" :
      $table_list = $tables["user"] . ',' . $tables["listuser"] . ',' . $tables["list"] . $findtables;
      $subselect = "{$tables["user"]}.id = {$tables["listuser"]}.userid and {$tables["listuser"]}.listid = {$tables["list"]}.id and {$tables["list"]}.owner = " . $_SESSION["logindetails"]["id"];
      if ($unconfirmed)
        $subselect .= ' and !confirmed ';
      if ($blacklisted)
        $subselect .= ' and blacklisted ';
      if ($find) {
        $listquery = "select DISTINCT {$tables["user"]}.email,{$tables["user"]}.id,$findfield,confirmed from " . $table_list . " where $subselect and $findbyselect";
        $count = Sql_query("SELECT count(distinct {$tables["user"]}.id) FROM " . $table_list . " where $subselect and $findbyselect");
        $unconfirmedcount = Sql_query("SELECT count(distinct {$tables["user"]}.id) FROM " . $table_list . " where $subselect and !confirmed and $findbyselect");
      } else {
        $listquery = "SELECT DISTINCT {$tables["user"]}.email,{$tables["user"]}.id,$findfield,confirmed FROM " . $table_list . " WHERE $subselect";
        $count = Sql_query("SELECT count(distinct {$tables["user"]}.id) FROM " . $table_list . " WHERE $subselect");
        $unconfirmedcount = Sql_query("SELECT count(distinct {$tables["user"]}.id) FROM " . $table_list . " WHERE !confirmed and $subselect");
      }
      break;
    case "all" :
    case "view" :
      $table_list = $tables["user"] . $findtables;
      if ($find) {
        if ($unconfirmed)
          $findbyselect .= ' and !confirmed ';
        if ($blacklisted)
          $findbyselect .= ' and blacklisted ';
        $listquery = "select DISTINCT {$tables["user"]}.email,{$tables["user"]}.id,$findfield,{$tables["user"]}.confirmed from " . $table_list . " where $findbyselect";
        $count = Sql_query("SELECT count(*) FROM " . $table_list . " where $findbyselect");
        $unconfirmedcount = Sql_query("SELECT count(*) FROM " . $table_list . " where !confirmed && $findbyselect");
      } else {
        $listquery = "select DISTINCT {$tables["user"]}.email,{$tables["user"]}.id,$findfield,{$tables["user"]}.confirmed from " . $table_list;
        $count = Sql_query("SELECT count(*) FROM " . $table_list);
        $unconfirmedcount = Sql_query("SELECT count(*) FROM " . $table_list . " where !confirmed");
        $searchdone = 0;
      }
{'fraction_non_alphanumeric': 0.222442663280692, 'fraction_numerical': 0.0016665344020315848, 'mean_word_length': 3.895881895881896, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6123913', 'n_tokens_mistral': 4305, 'n_tokens_neox': 4279, 'n_words': 868}