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

/edit_post_details.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 289 lines | 227 code | 43 blank | 19 comment | 38 complexity | dbeb007bd8e54552ef6a4031e221909f 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. define('IN_ICYPHOENIX', true);
  11. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './');
  12. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  13. include(IP_ROOT_PATH . 'common.' . PHP_EXT);
  14. include_once(IP_ROOT_PATH . 'includes/functions_post.' . PHP_EXT);
  15. if (!class_exists('class_mcp')) include(IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT);
  16. if (empty($class_mcp)) $class_mcp = new class_mcp();
  17. // Start session management
  18. $user->session_begin();
  19. $auth->acl($user->data);
  20. $user->setup();
  21. // End session management
  22. if ($user->data['user_level'] != ADMIN)
  23. {
  24. message_die(GENERAL_MESSAGE, $lang['Not_Authorized']);
  25. }
  26. // Get the needes values from post
  27. $submit = '';
  28. $post_id = 0;
  29. $topic_id = 0;
  30. $edit_post_time = '';
  31. $s_days = '';
  32. $s_months = '';
  33. $s_year = '';
  34. $s_hours = '';
  35. $s_minutes = '';
  36. $s_seconds = '';
  37. $topic_post_time = '';
  38. $topic_id = request_var(POST_TOPIC_URL, 0);
  39. $topic_id = ($topic_id < 0) ? 0 : $topic_id;
  40. $post_id = request_var(POST_POST_URL, 0);
  41. $post_id = ($post_id < 0) ? 0 : $post_id;
  42. // Get the submitted values, if a submit was send
  43. $submit = (!empty($_POST['submit'])) ? $_POST['submit'] : $_GET['submit'];
  44. // Submit if submit is given
  45. if ($submit)
  46. {
  47. $new_poster = request_var('username', '', true);
  48. $new_poster = (!empty($new_poster) ? phpbb_clean_username($new_poster) : '');
  49. $topic_post = request_var('topic_post', '');
  50. $twelve_hours = request_var('twelve_hours', '');
  51. $new_day = request_var($topic_post . '_day', 0);
  52. $month = request_var($topic_post . '_month', 0);
  53. $year = request_var($topic_post . '_year', 0);
  54. $hour = request_var($topic_post . '_hour', 0);
  55. $minute = request_var($topic_post . '_minute', 0);
  56. $second = request_var($topic_post . '_second', 0);
  57. $am_pm_s = request_var($topic_post . '_ampm', '');
  58. if (($am_pm_s == 'pm') && !empty($twelve_hours))
  59. {
  60. $hour += 12;
  61. }
  62. $edit_post_time = gmmktime($hour, $minute, $second, $month, $new_day, $year);
  63. $dst_sec = get_dst($edit_post_time, $config['board_timezone']);
  64. $edit_post_time = $edit_post_time - (3600 * $config['board_timezone']) - $dst_sec;
  65. $time_changed = $class_mcp->post_change_time($post_id, $edit_post_time);
  66. if (!empty($new_poster))
  67. {
  68. $poster_changed = $class_mcp->post_change_poster($post_id, $new_poster);
  69. }
  70. if (!empty($post_id))
  71. {
  72. $sql = "SELECT forum_id, topic_id FROM " . POSTS_TABLE . " WHERE post_id = '" . $post_id . "' LIMIT 1";
  73. $result = $db->sql_query($sql);
  74. $post_data = $db->sql_fetchrow($result);
  75. if (!empty($post_data['forum_id']) && !empty($post_data['topic_id']))
  76. {
  77. $class_mcp->sync_topic_details($post_data['topic_id'], $post_data['forum_id'], false, false);
  78. }
  79. }
  80. $template->assign_block_vars('submit_finished', array());
  81. $template->assign_vars(array(
  82. 'L_POST_EDIT_TIME' => $lang['Edit_post_time'],
  83. 'L_TIME' => ($topic_post_time == 'topic') ? $lang['Topic_time_xs'] : $lang['Post_time'],
  84. 'CLOSE' => true,
  85. 'POST_EDIT_STRING' => $lang['DETAILS_CHANGED'],
  86. 'U_VIEWTOPIC' => append_sid(CMS_PAGE_VIEWTOPIC . '?' . POST_POST_URL . '=' . $post_id . '#p' . $post_id)
  87. )
  88. );
  89. }
  90. else
  91. {
  92. // Check a post id was given
  93. if ($post_id == 0)
  94. {
  95. message_die(GENERAL_MESSAGE, $lang['No_post_id']);
  96. }
  97. // Check a topic_id was given and read it if not
  98. if ($topic_id == 0)
  99. {
  100. $sql = "SELECT p.topic_id
  101. FROM " . POSTS_TABLE . " p
  102. WHERE p.post_id = '" . $post_id . "'";
  103. $result = $db->sql_query($sql);
  104. while ($row = $db->sql_fetchrow($result))
  105. {
  106. $topic_id = $row['topic_id'];
  107. }
  108. $db->sql_freeresult($result);
  109. }
  110. // Check the post is first post in topic or not
  111. $sql = "SELECT topic_first_post_id FROM " . TOPICS_TABLE . " WHERE topic_id = '" . $topic_id . "'";
  112. $result = $db->sql_query($sql);
  113. while ($row = $db->sql_fetchrow($result))
  114. {
  115. $topic_first_post_id = $row['topic_first_post_id'];
  116. }
  117. $db->sql_freeresult($result);
  118. // Read post or topic time
  119. if ($topic_first_post_id == $post_id)
  120. {
  121. $topic_post_time = 'topic';
  122. $sql = "SELECT t.topic_time, t.topic_poster, u.user_id, u.username, u.user_active, u.user_color
  123. FROM " . TOPICS_TABLE . " t, " . USERS_TABLE . " u
  124. WHERE t.topic_id = '" . $topic_id . "'
  125. AND u.user_id = t.topic_poster";
  126. $result = $db->sql_query($sql);
  127. while ($row = $db->sql_fetchrow($result))
  128. {
  129. $edit_post_time = $row['topic_time'];
  130. $poster_id = $row['topic_poster'];
  131. $poster_name = colorize_username($row['user_id'], $row['username'], $row['user_color'], $row['user_active']);
  132. }
  133. $db->sql_freeresult($result);
  134. }
  135. else
  136. {
  137. $topic_post_time = 'post';
  138. $sql = "SELECT p.post_time, p.poster_id, u.user_id, u.username, u.user_active, u.user_color
  139. FROM " . POSTS_TABLE . " p, " . USERS_TABLE . " u
  140. WHERE p.post_id = '" . $post_id . "'
  141. AND u.user_id = p.poster_id";
  142. $result = $db->sql_query($sql);
  143. while ($row = $db->sql_fetchrow($result))
  144. {
  145. $edit_post_time = $row['post_time'];
  146. $poster_id = $row['poster_id'];
  147. $poster_name = colorize_username($row['user_id'], $row['username'], $row['user_color'], $row['user_active']);
  148. }
  149. $db->sql_freeresult($result);
  150. }
  151. // Check user dateformat for output
  152. $twelve_hours = (strpos($user->data['user_dateformat'], 'g') || strpos($user->data['user_dateformat'], 'h')) ? true : 0;
  153. $am_pm = (strpos($user->data['user_dateformat'], 'a') || strpos($user->data['user_dateformat'], 'A')) ? true : 0;
  154. // Create the drop downs
  155. $s_hours = '<select name="' . $topic_post_time . '_hour">';
  156. for ($i = 0; $i < (($twelve_hours == true) ? 13 : 24); $i++)
  157. {
  158. $j = ($i < 10) ? '0'.$i : $i;
  159. $s_hours .= '<option value="'.$j.'">'.$j.'</option>';
  160. }
  161. $s_hours .= '</select>';
  162. $s_hours = str_replace('value="' . create_date((!empty($twelve_hours) ? 'h' : 'H'), $edit_post_time, $user->data['user_timezone']).'">', 'value="' . create_date((!empty($twelve_hours) ? 'h' : 'H'), $edit_post_time, $user->data['user_timezone']) . '" selected="selected">', $s_hours);
  163. $s_minutes = '<select name="' . $topic_post_time . '_minute">';
  164. $s_seconds = '<select name="' . $topic_post_time . '_second">';
  165. for ($i = 0; $i < 60; $i++)
  166. {
  167. $j = ($i < 10) ? '0'.$i : $i;
  168. $s_minutes .= '<option value="' . $j . '">' . $j . '</option>';
  169. $s_seconds .= '<option value="' . $j . '">' . $j . '</option>';
  170. }
  171. $s_minutes .= '</select>';
  172. $s_seconds .= '</select>';
  173. $s_minutes = str_replace('value="' . create_date('i', $edit_post_time, $user->data['user_timezone']) . '">', 'value="' . create_date('i', $edit_post_time, $user->data['user_timezone']) . '" selected="selected">', $s_minutes);
  174. $s_seconds = str_replace('value="' . create_date('s', $edit_post_time, $user->data['user_timezone']) . '">', 'value="' . create_date('s', $edit_post_time, $user->data['user_timezone']) . '" selected="selected">', $s_seconds);
  175. if ($am_pm == true)
  176. {
  177. $s_am_pm = '<select name="' . $topic_post_time . '_ampm">';
  178. $s_am_pm .= '<option value="am">AM</option>';
  179. $s_am_pm .= '<option value="pm">PM</option>';
  180. $s_am_pm .= '</select>';
  181. $s_am_pm = str_replace('value="' . create_date('a', $edit_post_time, $user->data['user_timezone']) . '">', 'value="' . create_date('a', $edit_post_time, $user->data['user_timezone']) . '" selected="selected">', $s_am_pm);
  182. }
  183. else
  184. {
  185. $s_am_pm = '';
  186. }
  187. $s_days = '<select name="' . $topic_post_time . '_day">';
  188. for ($i = 1; $i < 32; $i++)
  189. {
  190. $j = ($i < 10) ? '0'.$i : $i;
  191. $s_days .= '<option value="' . $j . '">' . $j . '</option>';
  192. }
  193. $s_days .= '</select>';
  194. $s_days = str_replace('value="' . create_date('d', $edit_post_time, $user->data['user_timezone']) . '">', 'value="' . create_date('d', $edit_post_time, $user->data['user_timezone']) . '" selected="selected">', $s_days);
  195. $s_months = '<select name="' . $topic_post_time . '_month">';
  196. $s_months .= '<option value="01">' . $lang['datetime']['January'] . '</option>';
  197. $s_months .= '<option value="02">' . $lang['datetime']['February'] . '</option>';
  198. $s_months .= '<option value="03">' . $lang['datetime']['March'] . '</option>';
  199. $s_months .= '<option value="04">' . $lang['datetime']['April'] . '</option>';
  200. $s_months .= '<option value="05">' . $lang['datetime']['May'] . '</option>';
  201. $s_months .= '<option value="06">' . $lang['datetime']['June'] . '</option>';
  202. $s_months .= '<option value="07">' . $lang['datetime']['July'] . '</option>';
  203. $s_months .= '<option value="08">' . $lang['datetime']['August'] . '</option>';
  204. $s_months .= '<option value="09">' . $lang['datetime']['September'] . '</option>';
  205. $s_months .= '<option value="10">' . $lang['datetime']['October'] . '</option>';
  206. $s_months .= '<option value="11">' . $lang['datetime']['November'] . '</option>';
  207. $s_months .= '<option value="12">' . $lang['datetime']['December'] . '</option>';
  208. $s_months .= '</select>';
  209. $s_months = str_replace('value="' . create_date('m', $edit_post_time, $user->data['user_timezone']) . '">', 'value="' . create_date('m', $edit_post_time, $user->data['user_timezone']) . '" selected="selected">', $s_months);
  210. $s_year = '<input type="text" class="post" size="4" maxlength="4" name="' . $topic_post_time . '_year" value="' . create_date('Y', $edit_post_time, $user->data['user_timezone']) . '" />';
  211. $date_sep = '&nbsp;.&nbsp;';
  212. $time_sep = '&nbsp;:&nbsp;';
  213. $blank_sep = '&nbsp;&nbsp;&nbsp;';
  214. if ($user->data['user_lang'] == 'english')
  215. {
  216. $post_edit_string = $s_months . $date_sep . $s_days . $date_sep . $s_year;
  217. }
  218. else
  219. {
  220. $post_edit_string = $s_days . $date_sep . $s_months . $date_sep . $s_year;
  221. }
  222. $post_edit_string .= $blank_sep . $s_hours . $time_sep . $s_minutes . $time_sep . $s_seconds . (($s_am_pm != '') ? $time_sep . $s_am_pm : '');
  223. $s_hidden_fields = '<input type="hidden" value="' . $topic_id . '" name="' . POST_TOPIC_URL . '" />';
  224. $s_hidden_fields .= '<input type="hidden" value="' . $post_id . '" name="' . POST_POST_URL . '" />';
  225. $s_hidden_fields .= '<input type="hidden" value="' . $topic_post_time . '" name="topic_post" />';
  226. $s_hidden_fields .= '<input type="hidden" value="' . $twelve_hours . '" name="twelve_hours" />';
  227. $s_hidden_fields .= ($s_am_pm == '') ? '<input type="hidden" value="" name="' . $topic_post_time . '_ampm" />' : '';
  228. $template->assign_block_vars('entry_page', array());
  229. $target_form_name = 'edit_post';
  230. $target_element_name = 'username';
  231. $template->assign_vars(array(
  232. 'L_POST_EDIT_TIME' => $lang['Edit_post_time'],
  233. 'L_TIME' => ($topic_post_time == 'topic') ? $lang['Topic_time_xs'] : $lang['Post_time'],
  234. 'L_SUBMIT' => $lang['Submit'],
  235. 'L_RESET' => $lang['Reset'],
  236. 'U_SEARCH_USER' => append_sid(CMS_PAGE_SEARCH . '?mode=searchuser&amp;target_form_name=' . $target_form_name . '&amp;target_element_name=' . $target_element_name),
  237. 'POSTER_NAME' => $poster_name,
  238. 'POST_EDIT_STRING' => $post_edit_string,
  239. 'S_ACTION' => append_sid('edit_post_details.' . PHP_EXT),
  240. 'S_HIDDEN_FIELDS' => $s_hidden_fields
  241. )
  242. );
  243. }
  244. $gen_simple_header = true;
  245. full_page_generation('edit_post_details_body.tpl', $lang['EDIT_POST_DETAILS'], '', '');
  246. ?>