Просмотр файла attach_mod/includes/functions_delete.php

Размер файла: 7.87Kb
  1. <?php
  2. /***************************************************************************
  3. * mides.ru
  4. * -------------------
  5. ***************************************************************************/
  6. if ( !defined('IN_PHPBB') )
  7. {
  8. die("ERROR!!! THIS FILE PROTECTED. IF YOU SAW THIS REPORT, MEANS HACKERS HERE IS NOTHING TO DO ");
  9. }
  10.  
  11. function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, $user_id = 0)
  12. {
  13. global $db;
  14.  
  15. if ($post_id_array === 0 && $attach_id_array === 0 && $page === 0)
  16. {
  17. return;
  18. }
  19.  
  20. if ($post_id_array === 0 && $attach_id_array !== 0)
  21. {
  22. $post_id_array = array();
  23.  
  24. if (!is_array($attach_id_array))
  25. {
  26. if (strstr($attach_id_array, ', '))
  27. {
  28. $attach_id_array = explode(', ', $attach_id_array);
  29. }
  30. else if (strstr($attach_id_array, ','))
  31. {
  32. $attach_id_array = explode(',', $attach_id_array);
  33. }
  34. else
  35. {
  36. $attach_id = intval($attach_id_array);
  37. $attach_id_array = array();
  38. $attach_id_array[] = $attach_id;
  39. }
  40. }
  41.  
  42. if ($page == PAGE_PRIVMSGS)
  43. {
  44. $p_id = 'privmsgs_id';
  45. }
  46. else
  47. {
  48. $p_id = 'post_id';
  49. }
  50.  
  51. $sql = "SELECT $p_id
  52. FROM " . ATTACHMENTS_TABLE . '
  53. WHERE attach_id IN (' . implode(', ', $attach_id_array) . ")
  54. GROUP BY $p_id";
  55.  
  56. if ( !($result = $db->sql_query($sql)) )
  57. {
  58. message_die(GENERAL_ERROR, 'Could not select ids', '', __LINE__, __FILE__, $sql);
  59. }
  60.  
  61. $num_post_list = $db->sql_numrows($result);
  62.  
  63. if ($num_post_list == 0)
  64. {
  65. $db->sql_freeresult($result);
  66. return;
  67. }
  68.  
  69. while ($row = $db->sql_fetchrow($result))
  70. {
  71. $post_id_array[] = intval($row[$p_id]);
  72. }
  73. $db->sql_freeresult($result);
  74. }
  75. if (!is_array($post_id_array))
  76. {
  77. if (trim($post_id_array) == '')
  78. {
  79. return;
  80. }
  81.  
  82. if (strstr($post_id_array, ', '))
  83. {
  84. $post_id_array = explode(', ', $post_id_array);
  85. }
  86. else if (strstr($post_id_array, ','))
  87. {
  88. $post_id_array = explode(',', $post_id_array);
  89. }
  90. else
  91. {
  92. $post_id = intval($post_id_array);
  93.  
  94. $post_id_array = array();
  95. $post_id_array[] = $post_id;
  96. }
  97. }
  98. if (!sizeof($post_id_array))
  99. {
  100. return;
  101. }
  102.  
  103. if ($attach_id_array === 0)
  104. {
  105. $attach_id_array = array();
  106.  
  107. if ($page == PAGE_PRIVMSGS)
  108. {
  109. $whereclause = 'WHERE privmsgs_id IN (' . implode(', ', $post_id_array) . ')';
  110. }
  111. else
  112. {
  113. $whereclause = 'WHERE post_id IN (' . implode(', ', $post_id_array) . ')';
  114. }
  115. $sql = 'SELECT attach_id
  116. FROM ' . ATTACHMENTS_TABLE . " $whereclause
  117. GROUP BY attach_id";
  118.  
  119. if ( !($result = $db->sql_query($sql)) )
  120. {
  121. message_die(GENERAL_ERROR, 'Could not select Attachment Ids', '', __LINE__, __FILE__, $sql);
  122. }
  123.  
  124. $num_attach_list = $db->sql_numrows($result);
  125.  
  126. if ($num_attach_list == 0)
  127. {
  128. $db->sql_freeresult($result);
  129. return;
  130. }
  131.  
  132. while ($row = $db->sql_fetchrow($result))
  133. {
  134. $attach_id_array[] = (int) $row['attach_id'];
  135. }
  136. $db->sql_freeresult($result);
  137. }
  138. if (!is_array($attach_id_array))
  139. {
  140. if (strstr($attach_id_array, ', '))
  141. {
  142. $attach_id_array = explode(', ', $attach_id_array);
  143. }
  144. else if (strstr($attach_id_array, ','))
  145. {
  146. $attach_id_array = explode(',', $attach_id_array);
  147. }
  148. else
  149. {
  150. $attach_id = intval($attach_id_array);
  151.  
  152. $attach_id_array = array();
  153. $attach_id_array[] = $attach_id;
  154. }
  155. }
  156.  
  157. if (!sizeof($attach_id_array))
  158. {
  159. return;
  160. }
  161.  
  162. if ($page == PAGE_PRIVMSGS)
  163. {
  164. $sql_id = 'privmsgs_id';
  165. if ($user_id)
  166. {
  167. $post_id_array_2 = array();
  168.  
  169. $sql = 'SELECT privmsgs_id, privmsgs_type, privmsgs_to_userid, privmsgs_from_userid
  170. FROM ' . PRIVMSGS_TABLE . '
  171. WHERE privmsgs_id IN (' . implode(', ', $post_id_array) . ')';
  172. if ( !($result = $db->sql_query($sql)) )
  173. {
  174. message_die(GENERAL_ERROR, 'Couldn\'t get Privmsgs Type', '', __LINE__, __FILE__, $sql);
  175. }
  176.  
  177. while ($row = $db->sql_fetchrow($result))
  178. {
  179. $privmsgs_type = $row['privmsgs_type'];
  180. if ($privmsgs_type == PRIVMSGS_READ_MAIL || $privmsgs_type == PRIVMSGS_NEW_MAIL || $privmsgs_type == PRIVMSGS_UNREAD_MAIL)
  181. {
  182. if ($row['privmsgs_to_userid'] == $user_id)
  183. {
  184. $post_id_array_2[] = $row['privmsgs_id'];
  185. }
  186. }
  187. else if ($privmsgs_type == PRIVMSGS_SENT_MAIL)
  188. {
  189. if ($row['privmsgs_from_userid'] == $user_id)
  190. {
  191. $post_id_array_2[] = $row['privmsgs_id'];
  192. }
  193. }
  194. else if ($privmsgs_type == PRIVMSGS_SAVED_OUT_MAIL)
  195. {
  196. if ($row['privmsgs_from_userid'] == $user_id)
  197. {
  198. $post_id_array_2[] = $row['privmsgs_id'];
  199. }
  200. }
  201. else if ($privmsgs_type == PRIVMSGS_SAVED_IN_MAIL)
  202. {
  203. if ($row['privmsgs_to_userid'] == $user_id)
  204. {
  205. $post_id_array_2[] = $row['privmsgs_id'];
  206. }
  207. }
  208. }
  209. $db->sql_freeresult($result);
  210. $post_id_array = $post_id_array_2;
  211. }
  212. }
  213. else
  214. {
  215. $sql_id = 'post_id';
  216. }
  217.  
  218. if (sizeof($post_id_array) && sizeof($attach_id_array))
  219. {
  220. $sql = 'DELETE FROM ' . ATTACHMENTS_TABLE . '
  221. WHERE attach_id IN (' . implode(', ', $attach_id_array) . ")
  222. AND $sql_id IN (" . implode(', ', $post_id_array) . ')';
  223.  
  224. if ( !($db->sql_query($sql)) )
  225. {
  226. message_die(GENERAL_ERROR, $lang['Error_deleted_attachments'], '', __LINE__, __FILE__, $sql);
  227. }
  228. for ($i = 0; $i < sizeof($attach_id_array); $i++)
  229. {
  230. $sql = 'SELECT attach_id
  231. FROM ' . ATTACHMENTS_TABLE . '
  232. WHERE attach_id = ' . (int) $attach_id_array[$i];
  233. if ( !($result = $db->sql_query($sql)) )
  234. {
  235. message_die(GENERAL_ERROR, 'Could not select Attachment Ids', '', __LINE__, __FILE__, $sql);
  236. }
  237. $num_rows = $db->sql_numrows($result);
  238. $db->sql_freeresult($result);
  239.  
  240. if ($num_rows == 0)
  241. {
  242. $sql = 'SELECT attach_id, physical_filename, thumbnail
  243. FROM ' . ATTACHMENTS_DESC_TABLE . '
  244. WHERE attach_id = ' . (int) $attach_id_array[$i];
  245. if ( !($result = $db->sql_query($sql)) )
  246. {
  247. message_die(GENERAL_ERROR, 'Couldn\'t query attach description table', '', __LINE__, __FILE__, $sql);
  248. }
  249. $num_rows = $db->sql_numrows($result);
  250.  
  251. if ($num_rows != 0)
  252. {
  253. $num_attach = $num_rows;
  254. $attachments = $db->sql_fetchrowset($result);
  255. $db->sql_freeresult($result);
  256.  
  257. // delete attachments
  258. for ($j = 0; $j < $num_attach; $j++)
  259. {
  260. unlink_attach($attachments[$j]['physical_filename']);
  261. if (intval($attachments[$j]['thumbnail']) == 1)
  262. {
  263. unlink_attach($attachments[$j]['physical_filename'], MODE_THUMBNAIL);
  264. }
  265. $sql = 'DELETE FROM ' . ATTACHMENTS_DESC_TABLE . '
  266. WHERE attach_id = ' . (int) $attachments[$j]['attach_id'];
  267.  
  268. if ( !($db->sql_query($sql)) )
  269. {
  270. message_die(GENERAL_ERROR, $lang['Error_deleted_attachments'], '', __LINE__, __FILE__, $sql);
  271. }
  272. }
  273. }
  274. else
  275. {
  276. $db->sql_freeresult($result);
  277. }
  278. }
  279. }
  280. }
  281.  
  282. if ($page == PAGE_PRIVMSGS)
  283. {
  284. for ($i = 0; $i < sizeof($post_id_array); $i++)
  285. {
  286. $sql = 'SELECT attach_id
  287. FROM ' . ATTACHMENTS_TABLE . '
  288. WHERE privmsgs_id = ' . (int) $post_id_array[$i];
  289.  
  290. if ( !($result = $db->sql_query($sql)) )
  291. {
  292. message_die(GENERAL_ERROR, 'Couldn\'t query Attachments Table', '', __LINE__, __FILE__, $sql);
  293. }
  294. $num_rows = $db->sql_numrows($result);
  295. $db->sql_freeresult($result);
  296.  
  297. if ($num_rows == 0)
  298. {
  299. $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' SET privmsgs_attachment = 0
  300. WHERE privmsgs_id = ' . $post_id_array[$i];
  301.  
  302. if ( !($result = $db->sql_query($sql)) )
  303. {
  304. message_die(GENERAL_ERROR, 'Couldn\'t update Private Message Attachment Switch', '', __LINE__, __FILE__, $sql);
  305. }
  306. }
  307. }
  308. }
  309. else
  310. {
  311. if (sizeof($post_id_array))
  312. {
  313. $sql = 'SELECT topic_id
  314. FROM ' . POSTS_TABLE . '
  315. WHERE post_id IN (' . implode(', ', $post_id_array) . ')
  316. GROUP BY topic_id';
  317. if ( !($result = $db->sql_query($sql)) )
  318. {
  319. message_die(GENERAL_ERROR, 'Couldn\'t select Topic ID', '', __LINE__, __FILE__, $sql);
  320. }
  321. while ($row = $db->sql_fetchrow($result))
  322. {
  323. attachment_sync_topic($row['topic_id']);
  324. }
  325. $db->sql_freeresult($result);
  326. }
  327. }
  328. }
  329.  
  330. ?>