PageRenderTime 22ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/mailz/lists/admin/users.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 326 lines | 296 code | 24 blank | 6 comment | 69 complexity | bd43a5a8386069da9f220b52ac5e46ae MD5 | raw file
  1. <?php
  2. ####################################################################
  3. # This file is a placeholder. Functionality is passed to commonlib #
  4. ####################################################################
  5. require_once dirname(__FILE__).'/accesscheck.php';
  6. $columns = array("messages","lists","bounces","rss","blacklist");
  7. include dirname(__FILE__).'/commonlib/pages/users.php';
  8. return;
  9. if (!$_SESSION["userlistfilter"]) {
  10. $_SESSION["userlistfilter"] = array();
  11. }
  12. if (isset($_GET["find"])) {
  13. if ($_GET["find"] == "NULL") {
  14. $_SESSION["userlistfilter"]["find"] = "";
  15. $_SESSION["userlistfilter"]["findby"] = "";
  16. } else {
  17. $_SESSION["userlistfilter"]["find"] = $_GET["find"];
  18. $_SESSION["userlistfilter"]["findby"] = $_GET["findby"];
  19. }
  20. }
  21. $find = $_SESSION["userlistfilter"]["find"];
  22. $findby = $_SESSION["userlistfilter"]["findby"];
  23. if (!$findby) {
  24. $findby = "email";
  25. }
  26. # hmm interesting, if they select a findby but not a find, use the Sql wildcard:
  27. if ($findby && !$find)
  28. $find = '%';
  29. $system_findby = array("email","foreignkey");
  30. if ($findby && $find && !in_array($findby,$system_findby) ) {
  31. $find_url = '&find='.urlencode($find)."&findby=".urlencode($findby);
  32. $findatt = Sql_Fetch_Array_Query("select id,tablename,type,name from {$tables["attribute"]} where id = $findby");
  33. switch ($findatt["type"]) {
  34. case "textline":
  35. case "hidden":
  36. $findtables = ','.$tables["user_attribute"];
  37. $findbyselect = sprintf(' %s.userid = %s.id and
  38. %s.attributeid = %d and %s.value like "%%%s%%"',
  39. $tables["user_attribute"],
  40. $tables["user"],
  41. $tables["user_attribute"],
  42. $findby,
  43. $tables["user_attribute"],
  44. $find
  45. );
  46. $findfield = $tables["user_attribute"].".value as display, ".$tables["user"].".bouncecount";
  47. $findfieldname = $findatt["name"];
  48. break;
  49. case "select":
  50. case "radio":
  51. $findtables = ','.$tables["user_attribute"].','.$table_prefix.'listattr_'.$findatt["tablename"];
  52. $findbyselect = sprintf(' %s.userid = %s.id and
  53. %s.attributeid = %d and %s.value = %s.id and
  54. %s.name like "%%%s%%"',
  55. $tables["user_attribute"],
  56. $tables["user"],
  57. $tables["user_attribute"],
  58. $findby,
  59. $tables["user_attribute"],
  60. $table_prefix.'listattr_'.$findatt["tablename"],
  61. $table_prefix.'listattr_'.$findatt["tablename"],
  62. $find);
  63. $findfield = $table_prefix.'listattr_'.$findatt["tablename"].".name as display, ".$tables["user"].".bouncecount";
  64. $findfieldname = $findatt["name"];
  65. break;
  66. }
  67. } else {
  68. $findtables = '';
  69. $findbyselect = sprintf(' %s like "%%%s%%"',$findby,$find);;
  70. $findfield = $tables["user"].".bouncecount,".$tables["user"].".rssfrequency,".$tables["user"].".foreignkey";
  71. $findfieldname = "Email";
  72. $find_url = '&find='.urlencode($find);
  73. }
  74. if ($require_login && !isSuperUser()) {
  75. $access = accessLevel("users");
  76. switch ($access) {
  77. case "owner":
  78. $table_list = $tables["user"].','.$tables["listuser"].','.$tables["list"].$findtables;
  79. $subselect = "{$tables["user"]}.id = {$tables["listuser"]}.userid and {$tables["listuser"]}.listid = {$tables["list"]}.id and {$tables["list"]}.owner = ".$_SESSION["logindetails"]["id"];
  80. if ($find) {
  81. $listquery = "select {$tables["user"]}.email,{$tables["user"]}.id,$findfield,confirmed from ".$table_list." where $subselect and $findbyselect";
  82. $count = Sql_query("SELECT count({$tables["user"]}.id) FROM ".$table_list ." where $subselect and $findbyselect");
  83. $unconfirmedcount = Sql_query("SELECT count({$tables["user"]}.id) FROM ".$table_list ." where $subselect and !confirmed and $findbyselect");
  84. } else {
  85. $listquery = "select {$tables["user"]}.email,{$tables["user"]}.id,$findfield,confirmed from ".$table_list." where $subselect";
  86. $count = Sql_query("SELECT count({$tables["user"]}.id) FROM ".$table_list ." where $subselect");
  87. $unconfirmedcount = Sql_query("SELECT count({$tables["user"]}.id) FROM ".$table_list ." where !confirmed and $subselect");
  88. }
  89. if ($_GET["unconfirmed"])
  90. $listquery .= ' and !confirmed ';
  91. if ($_GET["blacklisted"])
  92. $listquery .= ' and blacklisted ';
  93. break;
  94. case "all":
  95. case "view":
  96. $table_list = $tables["user"].$findtables;
  97. if ($find) {
  98. $listquery = "select {$tables["user"]}.email,{$tables["user"]}.id,$findfield,{$tables["user"]}.confirmed from ".$table_list." where $findbyselect";
  99. $count = Sql_query("SELECT count(*) FROM ".$table_list ." where $findbyselect");
  100. $unconfirmedcount = Sql_query("SELECT count(*) FROM ".$table_list ." where !confirmed && $findbyselect");
  101. if ($_GET["unconfirmed"])
  102. $listquery .= ' and !confirmed ';
  103. if ($_GET["blacklisted"])
  104. $listquery .= ' and blacklisted ';
  105. } else {
  106. $listquery = "select {$tables["user"]}.email,{$tables["user"]}.id,$findfield,{$tables["user"]}.confirmed from ".$table_list;
  107. $count = Sql_query("SELECT count(*) FROM ".$table_list);
  108. $unconfirmedcount = Sql_query("SELECT count(*) FROM ".$table_list." where !confirmed");
  109. }
  110. $delete_message = '<br />Delete will delete user and all listmemberships<br />';
  111. break;
  112. case "none":
  113. default:
  114. print Error("Your privileges for this page are insufficient");
  115. return;
  116. }
  117. $delete_message = '<br />Delete will delete user from the list<br />';
  118. } else {
  119. $table_list = $tables["user"].$findtables;
  120. if ($find) {
  121. $listquery = "select {$tables["user"]}.email,{$tables["user"]}.id,$findfield,{$tables["user"]}.confirmed from ".$table_list." where $findbyselect";
  122. $count = Sql_query("SELECT count(*) FROM ".$table_list ." where $findbyselect");
  123. $unconfirmedcount = Sql_query("SELECT count(*) FROM ".$table_list ." where !confirmed and $findbyselect");
  124. if ($_GET["unconfirmed"])
  125. $listquery .= ' and !confirmed ';
  126. if ($_GET["blacklisted"])
  127. $listquery .= ' and blacklisted ';
  128. } else {
  129. $listquery = "select {$tables["user"]}.email,{$tables["user"]}.id,$findfield,{$tables["user"]}.confirmed from ".$table_list;
  130. $count = Sql_query("SELECT count(*) FROM ".$table_list);
  131. $unconfirmedcount = Sql_query("SELECT count(*) FROM ".$table_list." where !confirmed");
  132. if ($_GET["unconfirmed"])
  133. $listquery .= ' where !confirmed';
  134. if ($_GET["blacklisted"])
  135. $listquery .= ' and blacklisted ';
  136. }
  137. $delete_message = '<br />Delete will delete user and all listmemberships<br />';
  138. }
  139. $totalres = Sql_fetch_Row($unconfirmedcount);
  140. $totalunconfirmed = $totalres[0];
  141. $totalres = Sql_fetch_Row($count);
  142. $total = $totalres[0];
  143. if (isset($delete)) {
  144. # delete the index in delete
  145. print "deleting $delete ..\n";
  146. deleteUser($delete);
  147. print "..Done<br><hr><br>\n";
  148. Redirect("users&start=$start");
  149. }
  150. ob_end_flush();
  151. if (isset($add)) {
  152. if (isset($new)) {
  153. $query = "insert into ".$tables["user"]." (email,entered) values(\"$new\",now())";
  154. $result = Sql_query($query);
  155. $userid = Sql_insert_id();
  156. $query = "insert into ".$tables["listuser"]." (userid,listid,entered) values($userid,$id,now())";
  157. $result = Sql_query($query);
  158. }
  159. echo "<br><font color=red size=+2>User added</font><br>";
  160. }
  161. print "$total Users";
  162. print $find ? " found": "";
  163. if ($find && !$findby && !$total) { # a search for an email has been done and not found
  164. print "<hr><h2>Add this user</h2>";
  165. $req = Sql_Query(sprintf('select * from %s where active',$tables["subscribepage"]));
  166. if (Sql_Affected_Rows()) {
  167. print "Click on a link to use the corresponding public subscribe page to add this user:";
  168. while ($row = Sql_Fetch_Array($req)) {
  169. printf('<p><a href="%s&id=%d&email=%s">%s</a></p>',getConfig("subscribeurl"),$row["id"],$find,$row["title"]);
  170. }
  171. } else {
  172. print "Click this link to use the public subscribe page to add this user:";
  173. printf('<p><a href="%s&email=%s">%s</a></p>',getConfig("subscribeurl"),$find,$GLOBALS["strSubscribeTitle"]);
  174. }
  175. print '<hr>';
  176. }
  177. print "<br/>Users marked <font color=red>red</font> are unconfirmed ($totalunconfirmed)<br/>";
  178. $url = getenv("REQUEST_URI");
  179. if ($_GET["unconfirmed"]) {
  180. $unc = "checked";
  181. } else {
  182. $unc = "unchecked";
  183. }
  184. if ($_GET["blacklisted"]) {
  185. $bll = "checked";
  186. } else {
  187. $bll = "unchecked";
  188. }
  189. print '<table><tr><td valign=top>';
  190. printf ('<form method="get" name="listcontrol">
  191. <input type=hidden name="page" value="users">
  192. <input type=hidden name="start" value="%s">
  193. <input type=hidden name="find" value="%s">
  194. <input type=hidden name="findby" value="%s"><br/>Show only unconfirmed users:
  195. <input type="checkbox" name="unconfirmed" value="on" %s><br/>Show only blacklisted users:
  196. <input type="checkbox" name="blacklisted" value="on" %s>',
  197. $start,$find,$findby,$unc,$bll);
  198. print '</td><td valign=top>';
  199. foreach (array("email","bouncecount","entered","modified","foreignkey") as $item) {
  200. $select .= sprintf('<option value="%s" %s>%s</option>',
  201. $item,$item == $sortby ? "selected":"",$item);
  202. }
  203. printf ('
  204. <br/>Sort by:
  205. <select name="sortby" onChange="document.listcontrol.submit();">
  206. <option value="0">-- default</option>
  207. %s
  208. </select>
  209. D: <input type=radio name="sortorder" value="desc" %s>
  210. A: <input type=radio name="sortorder" value="asc" %s>
  211. <input type=submit name="change" value="Go">
  212. ',
  213. $select,$sortorder == "desc"? "checked":"",$sortorder == "asc"? "checked":"");
  214. print '</td></tr></table>';
  215. if ($sortby) {
  216. $order = ' order by '.$sortby;
  217. if ($sortorder == "asc") {
  218. $order .= ' asc';
  219. } else {
  220. $order .= ' desc';
  221. }
  222. $find_url .= "&sortby=$sortby&sortorder=$sortorder&unconfirmed=$unconfirmed";
  223. }
  224. if ($total > MAX_USER_PP) {
  225. if (isset($start) && $start) {
  226. $listing = "Listing user $start to " . ($start + MAX_USER_PP);
  227. $limit = "limit $start,".MAX_USER_PP;
  228. } else {
  229. $listing = "Listing user 1 to 50";
  230. $limit = "limit 0,50";
  231. $start = 0;
  232. }
  233. if ($_GET["unconfirmed"])
  234. $find_url .= "&unconfirmed=".$_GET["unconfirmed"];
  235. printf ('<table border=1><tr><td colspan=4 align=center>%s</td></tr><tr><td>%s</td><td>%s</td><td>
  236. %s</td><td>%s</td></tr></table><p><hr>',
  237. $listing,
  238. PageLink2("users","&lt;&lt;","start=0".$find_url),
  239. PageLink2("users","&lt;",sprintf('start=%d',max(0,$start-MAX_USER_PP)).$find_url),
  240. PageLink2("users","&gt;",sprintf('start=%d',min($total,$start+MAX_USER_PP)).$find_url),
  241. PageLink2("users","&gt;&gt;",sprintf('start=%d',$total-MAX_USER_PP).$find_url));
  242. $result = Sql_query("$listquery $order $limit");
  243. } else {
  244. $result = Sql_Query("$listquery $order");
  245. }
  246. ?>
  247. <table border=0>
  248. <tr><td colspan=4><input type=hidden name=id value="<?php echo $listid?>">
  249. Find a user: <input type=text name=find value="<?php echo $find != '%' ? $find : ""?>" size=30>
  250. <select name="findby"><option value="email" <?php echo $findby == "email"? "selected":""?>>Email</option>
  251. <option value="foreignkey" <?php echo $findby == "foreignkey"? "selected":""?>>Foreign Key</option>
  252. <?php
  253. $att_req = Sql_Query("select id,name from ".$tables["attribute"]." where type = \"hidden\" or type = \"textline\" or type = \"select\"");
  254. while ($row = Sql_Fetch_Array($att_req)) {
  255. printf('<option value="%d" %s>%s</option>',$row["id"],$row["id"] == $findby ? "selected":"",substr($row["name"],0,20));
  256. }
  257. ?></select><input type=submit value="Go">&nbsp;&nbsp;<a href="./?page=users&find=NULL">reset</a>
  258. </form></td></tr>
  259. <tr><td colspan=4>
  260. <?php
  261. #if (($require_login && isSuperUser()) || !$require_login)
  262. print PageLink2("dlusers","Download all users as CSV file","nocache=".uniqid(""));
  263. ?></td></tr>
  264. </table>
  265. <?php
  266. $some = 0;
  267. $ls = new WebblerListing("users");
  268. while ($user = Sql_fetch_array($result)) {
  269. $some = 1;
  270. $lists = Sql_query("SELECT count(*) FROM ".$tables["listuser"].",".$tables["list"]." where userid = ".$user["id"]." and ".$tables["listuser"].".listid = ".$tables["list"].".id");
  271. $membership = Sql_fetch_row($lists);
  272. $msgs = Sql_query("SELECT count(*) FROM ".$tables["usermessage"]." where userid = ".$user["id"]);
  273. $nummsgs = Sql_fetch_row($msgs);
  274. $onblacklist = isBlackListed($user["email"]);
  275. $ls->addElement($user["email"],PageURL2("user&start=$start&id=".$user["id"].$find_url));
  276. $ls->addColumn($user["email"],"confirmed",
  277. $user["confirmed"]?$GLOBALS["img_tick"]:$GLOBALS["img_cross"]);
  278. $ls->addColumn($user["email"],"bl l",
  279. $onblacklist?$GLOBALS["img_tick"]:$GLOBALS["img_cross"]);
  280. $ls->addColumn($user["email"],"del",sprintf("<a href=\"javascript:deleteRec('%s');\">del</a>",
  281. PageURL2("users","delete","start=$start&delete=".$user["id"])));
  282. $ls->addColumn($user["email"],"key",$user["foreignkey"]);
  283. $ls->addColumn($user["email"],"&nbsp;",$user["display"]);
  284. $ls->addColumn($user["email"],"lists",$membership[0]);
  285. $ls->addColumn($user["email"],"msgs",$nummsgs[0]);
  286. if (ENABLE_RSS) {
  287. $rss = Sql_query("SELECT count(*) FROM ".$tables["rssitem_user"]." where userid = ".$user["id"]);
  288. $nummsgs = Sql_fetch_row($rss);
  289. $ls->addColumn($user["email"],"rss",$nummsgs[0]);
  290. if ($user["rssfrequency"])
  291. $ls->addColumn($user["email"],"rss freq",$user["rssfrequency"]);
  292. $last = Sql_Fetch_Row_Query("select last from {$tables["user_rss"]} where userid = ".$user["id"]);
  293. if ($last[0])
  294. $ls->addColumn($user["email"],"last sent",$last[0]);
  295. }
  296. $ls->addColumn($user["email"],"bncs",$user["bouncecount"]);
  297. }
  298. print $ls->display();
  299. if (!$some) {
  300. print "<p>No users apply</p>";
  301. }
  302. ?>