PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/backend/admin_members.php

https://github.com/angelasabas/enthusiast-lite
PHP | 532 lines | 462 code | 28 blank | 42 comment | 14 complexity | 72b585fee0d306846af895360255066a MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /*****************************************************************************
  3. Enthusiast Lite: Fanlisting Management System
  4. Copyright (c) by Angela Sabas
  5. http://scripts.indisguise.org
  6. This program is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. For more information please view the readme.txt file.
  17. ******************************************************************************/
  18. session_start();
  19. require_once( 'config.inc.php' );
  20. // check if person is logged in
  21. if( !isset( $_COOKIE["login_password"] ) ||
  22. $_COOKIE['login_password'] != md5( $set_password . 'ENTH2' ) ) {
  23. // if person is not logged in, go to index page
  24. $_SESSION["login_message"] = 'Please log in first before viewing ' .
  25. 'anything.';
  26. header( 'location: index.php' );
  27. die( 'Redirecting you...' );
  28. }
  29. // include header and config files
  30. require_once( 'header.inc.php' );
  31. // show default page
  32. $show_default = true;
  33. ?>
  34. <p class="location">Enthusiast > Members</p>
  35. <?php
  36. /******************************************************************************
  37. Edit member information
  38. ******************************************************************************/
  39. if( isset( $_GET["action"] ) && $_GET["action"] == 'edit' ) {
  40. // show edit form, hide default page
  41. $show_edit_form = true;
  42. $show_default = false;
  43. if( isset( $_GET["done"] ) ) {
  44. // create query to update the information
  45. $query = 'UPDATE ' . $db_table . ' SET email = "' .
  46. $_GET["edit_email"] . '", name = "' .
  47. $_GET["edit_name"] . '", ';
  48. // if country is enabled, include country
  49. if( !isset( $disable_country ) || !$disable_country )
  50. $query .= ' country = "' . $_GET["edit_country"] .
  51. '", ';
  52. // if there is no url, make it null
  53. if( $_GET["edit_url"] == '' )
  54. $query .= 'url = null, ';
  55. else
  56. $query .= 'url = "' . $_GET["edit_url"] . '", ';
  57. // add aditional fields, if any, to query string
  58. if( $additional_field ) {
  59. // for each field name, add it to the query string
  60. foreach( $additional_field_names as $field ) {
  61. $query .= $db_table . '.' . $field . ' = "' .
  62. $_GET["edit_$field"] .'", ';
  63. }
  64. }
  65. // finish creating string
  66. $query .= 'showurl = ' . $_GET["edit_showurl"] . ' WHERE ' .
  67. 'email = "' . $_GET["email"] . '"';
  68. // connect to database
  69. $db_link = mysql_connect( $db_server, $db_user, $db_password )
  70. or die( 'Cannot connect to the MySQL server: ' .
  71. mysql_error() );
  72. mysql_select_db( $db_database )
  73. or die( 'Cannot select database: ' . mysql_error() );
  74. // run query
  75. mysql_query( $query )
  76. or die( 'Cannot execute query: ' . mysql_error() );
  77. // if no rows were affected, there's something wrong
  78. if( mysql_affected_rows() <= 0 )
  79. echo '<p class="important">Error editing member.' .
  80. ' Please try again.</p>';
  81. else {
  82. // editing was successful
  83. echo '<p>You have successfully edited the ' .
  84. 'information of the member ' .
  85. 'with the email address of ' .
  86. $_GET["email"] . '.</p>';
  87. // don't show edit form, but show default page
  88. $show_edit_form = false;
  89. $show_default = true;
  90. }
  91. // close database link
  92. mysql_close( $db_link );
  93. }
  94. // create edit form
  95. if( $show_edit_form ) {
  96. // get member information
  97. require_once( 'get_members.php' );
  98. $num = 0;
  99. $memberinfo = get_members( $_GET["email"], '', '', '', '',
  100. 2, '', '', '', $num );
  101. ?>
  102. <p>
  103. You can edit the member's information using the
  104. form below. Change only the fields you wish to change.
  105. </p>
  106. <form action="<?= $_SERVER["PHP_SELF"] ?>" method="get">
  107. <input type="hidden" name="action" value="edit" />
  108. <input type="hidden" name="done" />
  109. <input type="hidden" name="email" value="<?=
  110. $_GET["email"] ?>" />
  111. <p><table>
  112. <tr><td>
  113. Email address
  114. </td><td>
  115. <input type="text" name="edit_email" value="<?=
  116. $memberinfo[0]["email"] ?>" />
  117. </td></tr>
  118. <tr><td>
  119. Name
  120. </td><td>
  121. <input type="text" name="edit_name" value="<?=
  122. $memberinfo[0]["name"] ?>" />
  123. </td></tr>
  124. <?php
  125. // if country is enabled, show this form element
  126. if( !isset( $disable_country ) || !$disable_country ) {
  127. ?>
  128. <tr><td>
  129. Country
  130. </td><td>
  131. <select name="edit_country" />
  132. <option><?= $memberinfo[0]["country"] ?></option>
  133. <option value=""></option>
  134. <option value="">-----</option>
  135. <?php
  136. include 'countries.inc.php';
  137. ?>
  138. </select>
  139. </td></tr>
  140. <?php
  141. }
  142. ?>
  143. <tr><td>
  144. Website URL
  145. </td><td>
  146. <input type="text" name="edit_url" value="<?=
  147. $memberinfo[0]["url"] ?>" />
  148. </td></tr>
  149. <?php
  150. // if there are additional fields, show these form elements
  151. if( $additional_field ) {
  152. // for each additional field, show a form element
  153. foreach( $additional_field_names as $field ) {
  154. ?>
  155. <tr><td>
  156. <?= ucfirst( $field ) ?>
  157. </td><td>
  158. <input type="text" name="edit_<?= $field ?>"
  159. value="<?= $memberinfo[0]["$field"] ?>" />
  160. </td></tr>
  161. <?php
  162. }
  163. }
  164. ?>
  165. <tr><td colspan="2" class="leftalign">
  166. <?php
  167. // if showurl is set to yes, make "show" the selected value
  168. if( $memberinfo[0]["showurl"] == 1 ) {
  169. ?>
  170. <input type="radio" name="edit_showurl" value="1"
  171. checked="checked" /> Show Website URL<br />
  172. <input type="radio" name="edit_showurl" value="0" />
  173. Hide Website URL
  174. <?php
  175. }
  176. else { // else, make "hide" the selected value
  177. ?>
  178. <input type="radio" name="edit_showurl" value="1" />
  179. Show Website URL<br />
  180. <input type="radio" name="edit_showurl" value="0"
  181. checked="checked"/> Hide Website URL
  182. <?php
  183. }
  184. ?>
  185. </td></tr>
  186. <tr><td colspan="2">
  187. <input type="submit" value="Change information" />
  188. <input type="reset" value="Reset form values" />
  189. </td></tr>
  190. </table></p>
  191. </form>
  192. <?php
  193. }
  194. }
  195. /******************************************************************************
  196. Delete member from database.
  197. ******************************************************************************/
  198. if( isset( $_GET["action"] ) && $_GET["action"] == 'delete' ) {
  199. // create query
  200. $query = 'DELETE FROM ' . $db_table . ' WHERE email = "' .
  201. $_GET["email"] . '"';
  202. // connect to database
  203. $db_link = mysql_connect( $db_server, $db_user, $db_password )
  204. or die( 'Cannot connect to the MySQL server: ' .
  205. mysql_error() );
  206. mysql_select_db( $db_database )
  207. or die( 'Cannot select database: ' . mysql_error() );
  208. mysql_query( $query )
  209. or die( 'Cannot execute query: ' . mysql_error() );
  210. // if there are no affected rows (nothing deleted)
  211. if( mysql_affected_rows() <= 0 )
  212. echo '<p class="important">Error deleting member. Please' .
  213. ' try again.</p>';
  214. else
  215. echo '<p>You have successfully deleted the member with the ' .
  216. 'email address of ' . $_GET["email"] . '.</p>';
  217. mysql_close( $db_link );
  218. }
  219. /******************************************************************************
  220. Default page view
  221. ******************************************************************************/
  222. if( $show_default ) {
  223. ?>
  224. <p>
  225. You can manage your members using this page. Members are
  226. shown below,<br />
  227. and you can also do a search for members in the search criteria form
  228. below.
  229. </p>
  230. <p>
  231. To approve members, please go to the
  232. <a href="admin_pending.php">Pending</a> page.
  233. </p>
  234. <p>
  235. <table><tr><td>
  236. Total members:
  237. </td><td>
  238. <?php
  239. include 'get_member_count.php';
  240. ?>
  241. </td></tr>
  242. </table></p>
  243. <form method="get" action="<?= $_SERVER["PHP_SELF"] ?>">
  244. <input type="hidden" name="action" value="view" />
  245. <p><table><tr><td colspan="2">
  246. What are you looking for?
  247. </td></tr>
  248. <tr><td>
  249. Email address
  250. </td><td>
  251. <input type="text" name="search_email" />
  252. </td></tr>
  253. <tr><td>
  254. Name
  255. </td><td>
  256. <input type="text" name="search_name" />
  257. </td></tr>
  258. <?php
  259. // if country is enabled, show this form element
  260. if( !isset( $disable_country ) || !$disable_country ) {
  261. ?>
  262. <tr><td>
  263. Country
  264. </td><td>
  265. <select name="search_country" />
  266. <option value=""></option>
  267. <?php
  268. include 'countries.inc.php';
  269. ?>
  270. </select>
  271. </td></tr>
  272. <?php
  273. }
  274. ?>
  275. <tr><td>
  276. Website URL
  277. </td><td>
  278. <input type="text" name="search_url" />
  279. </td></tr>
  280. <?php
  281. // show form elements for each additional fields
  282. if( $additional_field ) {
  283. foreach( $additional_field_names as $field ) {
  284. ?>
  285. <tr><td>
  286. <?= ucfirst( $field ) ?>
  287. </td><td>
  288. <input type="text" name="edit_<?= $field ?>" />
  289. </td></tr>
  290. <?php
  291. }
  292. }
  293. ?>
  294. <tr><td>
  295. Date added
  296. </td><td>
  297. <input type="text" name="search_date_day" size="2" />
  298. <select name="search_date_month">
  299. <?php
  300. include( 'select_month.inc.php' );
  301. ?>
  302. <option value="" selected="selected">No month</option>
  303. </select>
  304. <select name="search_date_year">
  305. <?php
  306. include( 'select_year.inc.php' );
  307. ?>
  308. <option value="" selected="selected">No year</option>
  309. </select>
  310. </td></tr>
  311. <tr><td colspan="2">
  312. <input type="submit" value="Search for this record" />
  313. <input type="reset" value="Start criteria over" />
  314. </td></tr>
  315. </table></p>
  316. </form>
  317. <?php
  318. // set search criteria
  319. $search_email = '';
  320. $search_name = '';
  321. $search_country = '';
  322. $search_url = '';
  323. $search_extra = '';
  324. $search_date_day = '';
  325. $search_date_month = '';
  326. $search_date_year = '';
  327. if( isset( $_GET["search_email"] ) )
  328. $search_email = $_GET["search_email"];
  329. if( isset( $_GET["search_name"] ) )
  330. $search_name = $_GET["search_name"];
  331. if( isset( $_GET["search_country"] ) )
  332. $search_country = $_GET["search_country"];
  333. if( isset( $_GET["search_url"] ) )
  334. $search_url = $_GET["search_url"];
  335. if( isset( $_GET["search_extra"] ) )
  336. $search_extra = $_GET["search_extra"];
  337. if( isset( $_GET["search_date_day"] ) )
  338. $search_date_day = $_GET["search_date_day"];
  339. if( isset( $_GET["search_date_month"] ) )
  340. $search_date_month = $_GET["search_date_month"];
  341. if( isset( $_GET["search_date_year"] ) )
  342. $search_date_year = $_GET["search_date_year"];
  343. $total_members = 0;
  344. require_once( 'get_members.php' );
  345. $members_array = get_members( $search_email, $search_name,
  346. $search_country, $search_url, $search_extra, 0,
  347. $search_date_day, $search_date_month, $search_date_year,
  348. $total_members );
  349. $member_num = count( $members_array );
  350. // set multiple page browsing
  351. if( !( isset( $_GET["page"] ) ) || $_GET["page"] == '' ) {
  352. $browse_page = 0;
  353. }
  354. else {
  355. $browse_page = $_GET["page"];
  356. }
  357. $array_position = $browse_page * $fans_per_page;
  358. // determine where to start showing
  359. $start = $array_position;
  360. $end = $array_position + $fans_per_page;
  361. echo '<p><table width="95%"><tr>';
  362. echo '<td><b>Email</b></td>';
  363. echo '<td><b>Name</b></td>';
  364. if( !isset( $disable_country ) || !$disable_country )
  365. echo '<td><b>Country</b></td>';
  366. echo '<td><b>Website URL</b></td>';
  367. if( $additional_field )
  368. echo '<td><b>Additional fields</b></td>';
  369. echo '<td width="70"><b>Date</b></td>';
  370. echo '<td colspan="3"><b>Action</b></td>';
  371. echo '</tr>';
  372. if( !isset( $link_target ) )
  373. $link_target = '_top';
  374. // loop showing entries
  375. while( $start < $member_num && $start < $end ) {
  376. echo '<tr>';
  377. echo '<td>' . $members_array[$start]["email"] . '</td>';
  378. echo '<td>' . $members_array[$start]["name"] . '</td>';
  379. if( !isset( $disable_country ) || !$disable_country )
  380. echo '<td>' . $members_array[$start]["country"] .
  381. '</td>';
  382. echo '<td><a href="' . $members_array[$start]["url"] .
  383. '" target="' . $link_target . '">' .
  384. $members_array[$start]["url"] . '</a></td>';
  385. if( $additional_field ) {
  386. echo '<td>';
  387. foreach( $additional_field_names as $field ) {
  388. echo ucfirst( $field ) . ': ' .
  389. $members_array[$start]["$field"] .
  390. '<br />';
  391. }
  392. echo '</td>';
  393. }
  394. echo '<td>' . $members_array[$start]["added"] . '</td>';
  395. echo '<td class="actioncell"><a href="' .
  396. $_SERVER["PHP_SELF"] . '?action=edit' .
  397. '&email=' . $members_array[$start]["email"] .
  398. '"><img src="action_edit.gif"></a></td>';
  399. echo '<td class="actioncell"><a href="' .
  400. $_SERVER["PHP_SELF"] .
  401. '?action=delete' . '&email=' .
  402. $members_array[$start]["email"] .
  403. '" onclick="go=confirm(\'Are you sure you want to' .
  404. ' delete ' . $members_array[$start]["name"] . ' (' .
  405. $members_array[$start]["email"] . ')?\'); ' .
  406. 'return go;"><img src="action_delete.gif"></a></td>';
  407. echo '<td class="actioncell"><a href="admin_email.php' .
  408. '?type=single' . '&email=' .
  409. $members_array[$start]["email"] .
  410. '"><img src="action_email.gif"></a></td>';
  411. echo '</tr>';
  412. $start++;
  413. }
  414. echo '</table></p>';
  415. if( $member_num > $fans_per_page ) {
  416. $show_page_number = $member_num / $fans_per_page;
  417. $j = 0;
  418. $show = 1;
  419. $url = $_SERVER["PHP_SELF"] . '?action=view' .
  420. '&search_email=' . $search_email .
  421. '&search_name=' . $search_name .
  422. '&search_country=' . $search_country .
  423. '&search_date_day=' . $search_date_day .
  424. '&search_date_month=' . $search_date_month .
  425. '&search_date_year=' . $search_date_year;
  426. echo '<p>Go to page: ';
  427. while( $j < $show_page_number ) {
  428. echo '<a href="' . $url . '&page=' . $j . '">' .
  429. $show . '</a> ';
  430. $j++;
  431. $show++;
  432. }
  433. echo '</p>';
  434. }
  435. ?>
  436. <p><table><tr><td>
  437. Sum of all members falling in the search criteria:
  438. </td><td>
  439. <?= number_format( $total_members ) ?>
  440. </td></tr>
  441. </table></p>
  442. <?php
  443. }
  444. require_once( 'footer.inc.php' );
  445. ?>