PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/mailz/lists/admin/commonlib/pages/user.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 354 lines | 321 code | 20 blank | 13 comment | 119 complexity | 6281188645b188f45b1d7cf3aa22c962 MD5 | raw file
  1. <script language="Javascript" src="js/jslib.js" type="text/javascript"></script>
  2. <?php
  3. #if (!$_GET["id"] && !$_GET["delete"]) {
  4. # Fatal_Error("No such user");
  5. # return;
  6. #}
  7. $id = sprintf('%d',isset($_GET["id"]) ? $_GET['id']:0);
  8. $delete = sprintf('%d',isset($_GET['delete']) ? $_GET["delete"]:0);
  9. $date = new Date();
  10. $access = accessLevel("user");
  11. switch ($access) {
  12. case "owner":
  13. $subselect = sprintf(' and %s.owner = %d',$tables["list"],$_SESSION["logindetails"]["id"]);
  14. $subselect_where = sprintf(' where %s.owner = %d',$tables["list"],$_SESSION["logindetails"]["id"]);break;
  15. case "all":
  16. $subselect = "";break;
  17. case "view":
  18. $subselect = "";
  19. if (sizeof($_POST)) {
  20. print Error($GLOBALS['I18N']->get('You only have privileges to view this page, not change any of the information'));
  21. return;
  22. }
  23. break;
  24. case "none":
  25. default:
  26. $subselect = " and ".$tables["list"].".id = 0";
  27. $subselect_where = " where ".$tables["list"].".owner = 0";break;
  28. }
  29. if ($access != "all") {
  30. $delete_message = '<br />'.$GLOBALS['I18N']->get('Delete will delete user from the list').'<br />';
  31. } else {
  32. $delete_message = '<br />'.$GLOBALS['I18N']->get('Delete will delete user and all listmemberships').'<br />';
  33. }
  34. $usegroups = Sql_Table_exists("groups") && Sql_Table_exists('user_group');
  35. if ($_POST["change"] && ($access == "owner"|| $access == "all")) {
  36. if (!verifyToken()) {
  37. print Error($GLOBALS['I18N']->get('No Access'));
  38. return;
  39. }
  40. if (!$id) {
  41. $id = addNewUser($_POST['email']);
  42. $newuser = 1;
  43. }
  44. if (!$id) {
  45. print $GLOBALS['I18N']->get('Error adding user, please check that the user exists');
  46. return;
  47. }
  48. # read the current values to compare changes
  49. $old_data = Sql_Fetch_Array_Query(sprintf('select * from %s where id = %d',$tables["user"],$id));
  50. $old_data = array_merge($old_data,getUserAttributeValues('',$id));
  51. # and membership of lists
  52. $req = Sql_Query("select * from {$tables["listuser"]} where userid = $id");
  53. while ($row = Sql_Fetch_Array($req)) {
  54. $old_listmembership[$row["listid"]] = listName($row["listid"]);
  55. }
  56. while (list ($key,$val) = each ($struct)) {
  57. list($a,$b) = explode(":",$val[1]);
  58. if (!ereg("sys",$a) && $val[1]) {
  59. if ($key == "password" && ENCRYPTPASSWORD) {
  60. if (isset($_POST[$key]))
  61. Sql_Query("update {$tables["user"]} set $key = \"".md5($_POST[$key])."\" where id = $id");
  62. } else {
  63. Sql_Query("update {$tables["user"]} set $key = \"".sql_escape($_POST[$key])."\" where id = $id");
  64. }
  65. }
  66. elseif ((!$require_login || ($require_login && isSuperUser())) && $key == "confirmed")
  67. Sql_Query("update {$tables["user"]} set $key = \"".sql_escape($_POST[$key])."\" where id = $id");
  68. }
  69. if (is_array($_POST['attribute']))
  70. while (list($key,$val) = each ($_POST['attribute'])) {
  71. Sql_Query(sprintf('replace into %s (userid,attributeid,value)
  72. values(%d,%d,"%s")',$tables["user_attribute"],$id,$key,$val));
  73. }
  74. if (is_array($_POST["dateattribute"]))
  75. foreach ($_POST["dateattribute"] as $attid => $attname) {
  76. if (isset($_POST[normalize($attname).'_novalue'])) {
  77. $value = "";
  78. } else {
  79. $value = $date->getDate($attname);
  80. }
  81. Sql_Query(sprintf('replace into %s (userid,attributeid,value)
  82. values(%d,%d,"%s")',$tables["user_attribute"],$id,$attid,$value));
  83. }
  84. if (is_array($_POST['cbattribute'])) {
  85. while (list($key,$val) = each ($_POST['cbattribute'])) {
  86. if ($_POST['attribute'][$key] == "on") {
  87. Sql_Query(sprintf('replace into %s (userid,attributeid,value)
  88. values(%d,%d,"on")',$tables["user_attribute"],$id,$key));
  89. } else {
  90. Sql_Query(sprintf('replace into %s (userid,attributeid,value)
  91. values(%d,%d,"")',$tables["user_attribute"],$id,$key));
  92. }
  93. }
  94. }
  95. if (is_array($_POST['cbgroup'])) {
  96. while (list($key,$val) = each ($_POST['cbgroup'])) {
  97. $field = "cbgroup".$val;
  98. if (is_array($_POST[$field])) {
  99. $newval = array();
  100. foreach ($_POST[$field] as $fieldval) {
  101. array_push($newval,sprintf('%0'.$checkboxgroup_storesize.'d',$fieldval));
  102. }
  103. $value = join(",",$newval);
  104. }
  105. else
  106. $value = "";
  107. Sql_Query(sprintf('replace into %s (userid,attributeid,value)
  108. values(%d,%d,"%s")',$tables["user_attribute"],$id,$val,$value));
  109. }
  110. }
  111. if ($usegroups) {
  112. Sql_Query("delete from user_group where userid = $id");
  113. if (is_array($_POST["groups"])) {
  114. foreach ($_POST["groups"] as $group) {
  115. Sql_Query(sprintf('insert into user_group (userid,groupid) values(%d,%d)',$id,$group));
  116. print "<br/>".$GLOBALS['I18N']->get('User added to group').' '.groupName($group);
  117. }
  118. }
  119. }
  120. # submitting page now saves everything, so check is not necessary
  121. if ($subselect == "") {
  122. Sql_Query("delete from {$tables["listuser"]} where userid = $id");
  123. } else {
  124. # only unsubscribe from the lists of this admin
  125. $req = Sql_Query("select id from {$tables["list"]} $subselect_where");
  126. while ($row = Sql_Fetch_Row($req)) {
  127. Sql_Query("delete from {$tables["listuser"]} where userid = $id and listid = $row[0]");
  128. }
  129. }
  130. if (is_array($_POST["subscribe"])) {
  131. foreach ($_POST["subscribe"] as $ind => $lst) {
  132. Sql_Query("insert into {$tables["listuser"]} (userid,listid) values($id,$lst)");
  133. print '<br/>'.sprintf($GLOBALS['I18N']->get('User added to list %s'),ListName($lst));
  134. }
  135. print "<br/>";
  136. }
  137. $history_entry = '';
  138. $current_data = Sql_Fetch_Array_Query(sprintf('select * from %s where id = %d',$tables["user"],$id));
  139. $current_data = array_merge($current_data,getUserAttributeValues('',$id));
  140. foreach ($current_data as $key => $val) {
  141. if (!is_numeric($key))
  142. if ($old_data[$key] != $val && $key != "modified") {
  143. $history_entry .= "$key = $val\nchanged from $old_data[$key]\n";
  144. }
  145. }
  146. if (!$history_entry) {
  147. $history_entry = "\nNo userdata changed";
  148. }
  149. # check lists
  150. $req = Sql_Query("select * from {$tables["listuser"]} where userid = $id");
  151. while ($row = Sql_Fetch_Array($req)) {
  152. $listmembership[$row["listid"]] = listName($row["listid"]);
  153. }
  154. # i'll do this once I can test it on a 4.3 server
  155. #if (function_exists("array_diff_assoc")) {
  156. if (0) {
  157. # it requires 4.3
  158. $subscribed_to = array_diff_assoc($listmembership, $old_listmembership);
  159. $unsubscribed_from = array_diff_assoc($old_listmembership,$listmembership);
  160. foreach ($subscribed_to as $key => $desc) {
  161. $history_entry .= "Subscribed to $desc\n";
  162. }
  163. foreach ($unsubscribed_to as $key => $desc) {
  164. $history_entry .= "Unsubscribed from $desc\n";
  165. }
  166. } else {
  167. $history_entry .= "\nList subscriptions:\n";
  168. foreach ($old_listmembership as $key => $val) {
  169. $history_entry .= "Was subscribed to: $val\n";
  170. }
  171. foreach ($listmembership as $key => $val) {
  172. $history_entry .= "Is now subscribed to: $val\n";
  173. }
  174. if (!sizeof($listmembership)) {
  175. $history_entry .= "Not subscribed to any lists\n";
  176. }
  177. }
  178. addUserHistory($email,"Update by ".adminName($_SESSION["logindetails"]["id"]),$history_entry);
  179. if ($newuser) {
  180. Redirect("user&id=$id");
  181. exit;
  182. }
  183. Info($GLOBALS['I18N']->get('Changes saved'));
  184. }
  185. if (isset($delete) && $delete && $access != "view") {
  186. # delete the index in delete
  187. print $GLOBALS['I18N']->get('Deleting')." $delete ..\n";
  188. if ($require_login && !isSuperUser()) {
  189. $lists = Sql_query("SELECT listid FROM {$tables["listuser"]},{$tables["list"]} where userid = ".$delete." and $tables[listuser].listid = $tables[list].id $subselect ");
  190. while ($lst = Sql_fetch_array($lists))
  191. Sql_query("delete from {$tables["listuser"]} where userid = $delete and listid = $lst[0]");
  192. } else {
  193. deleteUser($delete);
  194. }
  195. print '..'.$GLOBALS['I18N']->get('Done')."<br /><hr><br />\n";
  196. }
  197. $membership = "";
  198. $subscribed = array();
  199. if ($id) {
  200. $result = Sql_query("SELECT * FROM {$tables["user"]} where id = $id");
  201. if (!Sql_Affected_Rows()) {
  202. Fatal_Error($GLOBALS['I18N']->get('No such User').' '.$id);
  203. return;
  204. }
  205. $user = sql_fetch_array($result);
  206. $lists = Sql_query("SELECT listid,name FROM {$tables["listuser"]},{$tables["list"]} where userid = ".$user["id"]." and $tables[listuser].listid = $tables[list].id $subselect ");
  207. while ($lst = Sql_fetch_array($lists)) {
  208. $membership .= "<li>".PageLink2("editlist",$lst["name"],"id=".$lst["listid"]);
  209. array_push($subscribed,$lst["listid"]);
  210. }
  211. if (!$membership)
  212. $membership = $GLOBALS['I18N']->get('No Lists');
  213. if ($access != "view")
  214. printf( "<br /><hr/>%s<li><a href=\"javascript:deleteRec('%s');\">delete</a> %s\n",
  215. $delete_message,PageURL2("user","","delete=$id&$returnurl"),$user["email"]);
  216. printf('&nbsp;&nbsp;<a href="%s">%s</a>',getConfig("preferencesurl").
  217. '&uid='.$user["uniqid"],$GLOBALS['I18N']->get('update page'));
  218. printf('&nbsp;&nbsp;<a href="%s">%s</a>',getConfig("unsubscribeurl").'&uid='.$user["uniqid"],$GLOBALS['I18N']->get('unsubscribe page'));
  219. print '&nbsp;&nbsp;'.PageLink2("userhistory&id=$id",$GLOBALS['I18N']->get('History'));
  220. } else {
  221. $user = array();
  222. $id = 0;
  223. print '<h1>'.$GLOBALS['I18N']->get('Add a new User').'</h1>';
  224. }
  225. print "<p><h3>".$GLOBALS['I18N']->get('User Details')."</h3>".formStart()."<table border=1>";
  226. print "<input type=hidden name=list value=$list><input type=hidden name=id value=$id>";
  227. print "<input type=hidden name=returnpage value=$returnpage><input type=hidden name=returnoption value=$returnoption>";
  228. reset($struct);
  229. while (list ($key,$val) = each ($struct)) {
  230. list($a,$b) = explode(":",$val[1]);
  231. if ($key == "confirmed") {
  232. if (!$require_login || ($require_login && isSuperUser())) {
  233. printf('<tr><td>%s (1/0)</td><td><input type="text" name="%s" value="%s" size=5></td></tr>'."\n",$GLOBALS['I18N']->get($b),$key,$user[$key]);
  234. } else {
  235. printf('<tr><td>%s</td><td>%s</td></tr>',$b,$user[$key]);
  236. }
  237. } elseif ($key == "password" && ENCRYPTPASSWORD) {
  238. printf('<tr><td>%s (%s)</td><td><input type="text" name="%s" value="%s" size=30></td></tr>'."\n",$GLOBALS['I18N']->get('encrypted'),$val[1],$key,"");
  239. } elseif ($key == "blacklisted") {
  240. printf('<tr><td>%s</td><td>%s</td></tr>',$GLOBALS['I18N']->get($b),isBlackListed($user['email']));
  241. } else {
  242. if (!strpos($key,'_')) {
  243. if (ereg("sys",$a))
  244. printf('<tr><td>%s</td><td>%s</td></tr>',$GLOBALS['I18N']->get($b),$user[$key]);
  245. elseif ($val[1])
  246. printf('<tr><td>%s</td><td><input type="text" name="%s" value="%s" size=30></td></tr>'."\n",$GLOBALS['I18N']->get($val[1]),$key,$user[$key]);
  247. }
  248. }
  249. }
  250. $res = Sql_Query("select * from $tables[attribute] order by listorder");
  251. while ($row = Sql_fetch_array($res)) {
  252. $val_req = Sql_Fetch_Row_Query("select value from $tables[user_attribute] where userid = $id and attributeid = $row[id]");
  253. $row["value"] = $val_req[0];
  254. if ($row["type"] == "date") {
  255. printf('<input style="attributeinput" type=hidden name="dateattribute[%d]" value="%s">',$row["id"],$row["name"]);
  256. $novalue = trim($row["value"]) == "" ? "checked":"";
  257. printf('<tr><td>%s<!--%s--></td><td>%s&nbsp; Not set: <input type=checkbox name="%s_novalue" %s></td></tr>'."\n",stripslashes($row["name"]),$row["value"],$date->showInput($row["name"],"",$row["value"]),normalize(stripslashes($row["name"])),$novalue);
  258. } elseif ($row["type"] == "checkbox") {
  259. $checked = $row["value"] == "on" ?"checked":"";
  260. printf('<tr><td>%s</td><td><input style="attributeinput" type=hidden name="cbattribute[%d]" value="%d"><input style="attributeinput" type=checkbox name="attribute[%d]" value="on" %s></td></tr>'."\n",stripslashes($row["name"]),$row["id"],$row["id"],$row["id"],$checked);
  261. } elseif ($row["type"] == "checkboxgroup") {
  262. printf ("<tr><td valign=top>%s</td><td>%s</td></tr>\n",stripslashes($row["name"]),UserAttributeValueCbGroup($id,$row["id"]));
  263. } elseif ($row["type"] == "textarea") {
  264. printf ('<tr><td valign=top>%s</td><td><textarea name="attribute[%d]" rows="10" cols="40" wrap=virtual>%s</textarea></td></tr>',stripslashes($row["name"]),$row["id"],htmlspecialchars($row["value"]));
  265. } else {
  266. if ($row["type"] != "textline" && $row["type"] != "hidden")
  267. printf ("<tr><td>%s</td><td>%s</td></tr>\n",stripslashes($row["name"]),UserAttributeValueSelect($id,$row["id"]));
  268. else
  269. printf('<tr><td>%s</td><td><input style="attributeinput" type=text name="attribute[%d]" value="%s" size=30></td></tr>'."\n",$row["name"],$row["id"],htmlspecialchars($row["value"]));
  270. }
  271. }
  272. if ($access != "view")
  273. print '<tr><td colspan=2><input type=submit name=change value="'.$GLOBALS['I18N']->get('Save Changes').'"></td></tr>';
  274. print '</table>';
  275. if (isBlackListed($user["email"])) {
  276. print '<h3>'.$GLOBALS['I18N']->get('User is blacklisted. No emails will be sent to this user').'</h3>';
  277. }
  278. print "<h3>".$GLOBALS['I18N']->get('Mailinglist Membership').":</h3>";
  279. print "<table border=1><tr>";
  280. $req = Sql_Query("select * from {$tables["list"]} $subselect_where order by listorder,name");
  281. $c = 0;
  282. while ($row = Sql_Fetch_Array($req)) {
  283. if (in_array($row["id"],$subscribed)) {
  284. $bgcol = '#F7E7C2';
  285. $subs = "checked";
  286. } else {
  287. $bgcol = '#ffffff';
  288. $subs = "";
  289. }
  290. printf ('<td bgcolor="%s"><input type=checkbox name="subscribe[]" value="%d" %s> %s</td>',
  291. $bgcol,$row["id"],$subs,PageLink2("editlist",stripslashes($row["name"]),"id=".$row["id"]));
  292. $c++;
  293. if ($c % 4 == 0)
  294. print '</tr><tr>';
  295. }
  296. print '</tr>';
  297. if ($access != "view")
  298. print '<tr><td><input type=submit name="change" value="'.$GLOBALS['I18N']->get('Save Changes').'"></td></tr>';
  299. print '</table>';
  300. if ($usegroups) {
  301. print "<h3>".$GLOBALS['I18N']->get('Group Membership').":</h3>";
  302. print "<table border=1><tr>";
  303. print '<tr><td colspan=2><hr width=50%></td></tr>
  304. <tr><td colspan=2>'.$GLOBALS['I18N']->get('Please select the groups this user is a member of').'</td></tr>
  305. <tr><td colspan=2>';
  306. $selected_groups = array();
  307. if ($id) {
  308. $req = Sql_Query("select groupid from user_group where userid = $id");
  309. while ($row = Sql_Fetch_Row($req))
  310. array_push($selected_groups,$row[0]);
  311. }
  312. $req = Sql_Query("select * from groups");
  313. $c = 1;
  314. while ($row = Sql_Fetch_array($req)) {
  315. if ($row["name"] != "Everyone") {
  316. printf ('<i>%s</i><input type=checkbox name="groups[]" value="%d" %s>&nbsp;&nbsp;',
  317. $row["name"],$row["id"],in_array($row["id"],$selected_groups)?"checked":""
  318. );
  319. } else {
  320. printf ('<b>%s</b>&nbsp;&nbsp;<input type=hidden name="groups[]" value="%d">',
  321. $row["name"],$row["id"]
  322. );
  323. }
  324. if ($c % 5 == 0)
  325. print "<br>";
  326. $c++;
  327. }
  328. print '</td></tr>';
  329. if ($access != "view")
  330. print '<tr><td><input type=submit name="change" value="'.$GLOBALS['I18N']->get('Save Changes').'"></td></tr>';
  331. print '</table>';
  332. }
  333. print '</form>';
  334. ?>