PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/album_comment_delete.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 195 lines | 110 code | 31 blank | 54 comment | 20 complexity | b6ef9f092f10bd7ddd7b8cecc0506c3b MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * Smartor (smartor_xp@hotmail.com)
  14. *
  15. */
  16. define('IN_ICYPHOENIX', true);
  17. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  18. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  19. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  20. // Start session management
  21. $user->session_begin();
  22. $auth->acl($user->data);
  23. $user->setup();
  24. // End session management
  25. // Get general album information
  26. include(ALBUM_MOD_PATH . 'album_common.' . PHP_EXT);
  27. // ------------------------------------
  28. // Check feature enabled
  29. // ------------------------------------
  30. if($album_config['comment'] == 0)
  31. {
  32. message_die(GENERAL_MESSAGE, $lang['Not_Authorized']);
  33. }
  34. // ------------------------------------
  35. // Check the request
  36. // ------------------------------------
  37. $comment_id = request_var('comment_id', 0);
  38. if(empty($comment_id))
  39. {
  40. message_die(GENERAL_ERROR, 'No comment_id specified');
  41. }
  42. // ------------------------------------
  43. // Get the comment info
  44. // ------------------------------------
  45. $sql = "SELECT *
  46. FROM ". ALBUM_COMMENT_TABLE ."
  47. WHERE comment_id = '$comment_id'";
  48. $result = $db->sql_query($sql);
  49. $thiscomment = $db->sql_fetchrow($result);
  50. if(empty($thiscomment))
  51. {
  52. message_die(GENERAL_ERROR, 'This comment does not exist');
  53. }
  54. // ------------------------------------
  55. // Get $pic_id from $comment_id
  56. // ------------------------------------
  57. $sql = "SELECT comment_id, comment_pic_id
  58. FROM ". ALBUM_COMMENT_TABLE ."
  59. WHERE comment_id = '$comment_id'";
  60. $result = $db->sql_query($sql);
  61. $row = $db->sql_fetchrow($result);
  62. if(empty($row))
  63. {
  64. message_die(GENERAL_ERROR, 'This comment does not exist');
  65. }
  66. $pic_id = $row['comment_pic_id'];
  67. // ------------------------------------
  68. // Get this pic info and current category info
  69. // ------------------------------------
  70. // NOTE: we don't do a left join here against the category table
  71. // since ALL pictures belong to some category, if not then it's database error
  72. $sql = "SELECT p.*, cat.*, u.user_id, u.username, COUNT(c.comment_id) as comments_count
  73. FROM ". ALBUM_CAT_TABLE ." AS cat, ". ALBUM_TABLE ." AS p
  74. LEFT JOIN ". USERS_TABLE ." AS u ON p.pic_user_id = u.user_id
  75. LEFT JOIN ". ALBUM_COMMENT_TABLE ." AS c ON p.pic_id = c.comment_pic_id
  76. WHERE pic_id = '$pic_id'
  77. AND cat.cat_id = p.pic_cat_id
  78. GROUP BY p.pic_id
  79. LIMIT 1";
  80. $result = $db->sql_query($sql);
  81. $thispic = $db->sql_fetchrow($result);
  82. $cat_id = $thispic['pic_cat_id'];
  83. $album_user_id = $thispic['cat_user_id'];
  84. $total_comments = $thispic['comments_count'];
  85. $comments_per_page = $config['posts_per_page'];
  86. $pic_filename = $thispic['pic_filename'];
  87. $pic_thumbnail = $thispic['pic_thumbnail'];
  88. if(empty($thispic))
  89. {
  90. message_die(GENERAL_ERROR, $lang['Pic_not_exist']);
  91. }
  92. // ------------------------------------
  93. // Check the permissions
  94. // ------------------------------------
  95. $album_user_access = album_permissions($album_user_id, $cat_id, ALBUM_AUTH_COMMENT|ALBUM_AUTH_DELETE, $thispic);
  96. if(($album_user_access['comment'] == 0) || ($album_user_access['delete'] == 0))
  97. {
  98. if (!$user->data['session_logged_in'])
  99. {
  100. redirect(append_sid(CMS_PAGE_LOGIN . '?redirect=album_comment_delete.' . PHP_EXT . '?comment_id=' . $comment_id));
  101. }
  102. else
  103. {
  104. message_die(GENERAL_ERROR, $lang['Not_Authorized']);
  105. }
  106. }
  107. else
  108. {
  109. if((!$album_user_access['moderator']) && ($user->data['user_level'] != ADMIN))
  110. {
  111. if ($thiscomment['comment_user_id'] != $user->data['user_id'])
  112. {
  113. message_die(GENERAL_ERROR, $lang['Not_Authorized']);
  114. }
  115. }
  116. }
  117. /*
  118. +----------------------------------------------------------
  119. | Main work here...
  120. +----------------------------------------------------------
  121. */
  122. if(!isset($_POST['confirm']))
  123. {
  124. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  125. Confirm Screen
  126. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  127. // --------------------------------
  128. // If user give up deleting...
  129. // --------------------------------
  130. if(isset($_POST['cancel']))
  131. {
  132. redirect(append_sid(album_append_uid('album_showpage.' . PHP_EXT . '?pic_id=' . $pic_id)));
  133. exit;
  134. }
  135. $template->assign_vars(array(
  136. 'MESSAGE_TITLE' => $lang['Confirm'],
  137. 'MESSAGE_TEXT' => $lang['Comment_delete_confirm'],
  138. 'L_NO' => $lang['No'],
  139. 'L_YES' => $lang['Yes'],
  140. 'S_CONFIRM_ACTION' => append_sid(album_append_uid('album_comment_delete.' . PHP_EXT . '?comment_id=' . $comment_id)),
  141. )
  142. );
  143. full_page_generation('confirm_body.tpl', $lang['Confirm'], '', '');
  144. }
  145. else
  146. {
  147. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  148. Do the deleting
  149. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  150. $sql = "DELETE
  151. FROM ". ALBUM_COMMENT_TABLE ."
  152. WHERE comment_id = '$comment_id'";
  153. $result = $db->sql_query($sql);
  154. // --------------------------------
  155. // Complete... now send a message to user
  156. // --------------------------------
  157. $message = $lang['Deleted'];
  158. $redirect_url = append_sid(album_append_uid('album_cat.' . PHP_EXT . '?cat_id=' . $cat_id));
  159. meta_refresh(3, $redirect_url);
  160. $message .= '<br /><br />' . sprintf($lang['Click_return_category'], '<a href="' . append_sid(album_append_uid('album_cat.' . PHP_EXT . '?cat_id=' . $cat_id)) . '">', '</a>');
  161. $message .= '<br /><br />' . sprintf($lang['Click_return_album_index'], '<a href="' . append_sid('album.' . PHP_EXT) . '">', '</a>');
  162. message_die(GENERAL_MESSAGE, $message);
  163. }
  164. ?>