PageRenderTime 27ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website trường trung học phổ thông PHP/lc1/modules/download/funcs/getcomment.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 312 lines | 265 code | 38 blank | 9 comment | 38 complexity | 1a1055bebf5a2aaca83cc6b0aed63ace MD5 | raw file
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.0
  4. * @Author VINADES.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES., JSC. All rights reserved
  6. * @Createdate 3-6-2010 0:30
  7. */
  8. if ( ! defined( 'NV_IS_MOD_DOWNLOAD' ) ) die( 'Stop!!!' );
  9. //if ( ! defined( 'NV_IS_AJAX' ) ) die( 'Wrong URL' );
  10. $list_cats = nv_list_cats( true );
  11. //dang thao luan
  12. if ( $nv_Request->isset_request( 'ajax', 'post' ) )
  13. {
  14. if ( ! empty( $list_cats ) )
  15. {
  16. $in = implode( ",", array_keys( $list_cats ) );
  17. $id = $nv_Request->get_int( 'id', 'post', 0 );
  18. $data = $error = array();
  19. if ( $id )
  20. {
  21. $query = "SELECT `who_comment`, `groups_comment` FROM `" . NV_PREFIXLANG . "_" . $module_data . "` WHERE `id`=" . $id . " AND `catid` IN (" . $in . ") AND `status`=1 AND `comment_allow`=1";
  22. $result = $db->sql_query( $query );
  23. $numrows = $db->sql_numrows( $result );
  24. if ( $numrows )
  25. {
  26. list( $who_comment, $groups_comment ) = $db->sql_fetchrow( $result );
  27. if ( nv_set_allow( $who_comment, $groups_comment ) )
  28. {
  29. $uname = filter_text_input( 'uname', 'post', '', 1 );
  30. $uemail = filter_text_input( 'uemail', 'post', '' );
  31. $subject = filter_text_input( 'subject', 'post', '', 1 );
  32. $content = filter_text_textarea( 'content', '', NV_ALLOWED_HTML_TAGS );
  33. $seccode = filter_text_input( 'seccode', 'post', '' );
  34. $post_id = 0;
  35. if ( defined( 'NV_IS_USER' ) )
  36. {
  37. $uname = ! empty( $user_info['full_name'] ) ? $user_info['full_name'] : $user_info['username'];
  38. $uemail = $user_info['email'];
  39. $post_id = $user_info['userid'];
  40. }
  41. if ( ! nv_capcha_txt( $seccode ) )
  42. {
  43. $error[] = $lang_module['comment_error2'];
  44. }
  45. if ( empty( $uname ) or nv_strlen( $uname ) < 3 )
  46. {
  47. $error[] = $lang_module['comment_error3'];
  48. }
  49. if ( ( $validemail = nv_check_valid_email( $uemail ) ) != "" )
  50. {
  51. $error[] = $validemail;
  52. }
  53. if ( empty( $subject ) or nv_strlen( $subject ) < 3 )
  54. {
  55. $error[] = $lang_module['comment_error4'];
  56. }
  57. if ( empty( $content ) or nv_strlen( $content ) < 3 )
  58. {
  59. $error[] = $lang_module['comment_error5'];
  60. }
  61. $download_config = initial_config_data();
  62. if ( $download_config['is_autocomment_allow'] )
  63. {
  64. $status = 1;
  65. }
  66. else
  67. {
  68. $status = 0;
  69. }
  70. if ( ! empty( $error ) )
  71. {
  72. echo implode( "\n", $error );
  73. die();
  74. }
  75. $content = nv_nl2br( $content, "<br />" );
  76. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_comments` VALUES (
  77. NULL,
  78. " . $id . ",
  79. " . $db->dbescape( $subject ) . ",
  80. " . $post_id . ",
  81. " . $db->dbescape( $uname ) . ",
  82. " . $db->dbescape( $uemail ) . ",
  83. " . $db->dbescape( $client_info['ip'] ) . ",
  84. " . NV_CURRENTTIME . ",
  85. " . $db->dbescape( $content ) . ",
  86. '', 0, " . $status . ")";
  87. if ( ! $db->sql_query_insert_id( $sql ) )
  88. {
  89. $error[] = $lang_module['comment_error6'];
  90. }
  91. if ( $status )
  92. {
  93. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "` SET `comment_hits`=comment_hits+1 WHERE `id`=" . $id;
  94. $db->sql_query( $sql );
  95. }
  96. if ( ! empty( $error ) )
  97. {
  98. echo implode( "\n", $error );
  99. die();
  100. }
  101. elseif ( $status == 1 )
  102. {
  103. die( "OK" );
  104. }
  105. else
  106. {
  107. die( "WAIT" );
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. //list_comment
  115. $generate_page = "";
  116. if ( $nv_Request->isset_request( 'list_comment', 'get' ) )
  117. {
  118. if ( ! empty( $list_cats ) )
  119. {
  120. $in = implode( ",", array_keys( $list_cats ) );
  121. $id = $nv_Request->get_int( 'list_comment', 'get', 0 );
  122. if ( $id )
  123. {
  124. $array = array();
  125. $users = array();
  126. $admins = array();
  127. $page = $nv_Request->get_int( 'page', 'get', 0 );
  128. $per_page = 15;
  129. $query = "SELECT SQL_CALC_FOUND_ROWS a.id AS id, a.subject AS subject, a.post_id AS post_id, a.post_name AS post_name, a.post_email AS post_email,
  130. a.post_ip AS post_ip, a.post_time AS post_time, a.comment AS comment, a.admin_reply AS admin_reply, a.admin_id AS admin_id,
  131. c.email as email, c.full_name as full_name, c.photo as photo, c.view_mail as view_mail
  132. FROM `" . NV_PREFIXLANG . "_" . $module_data . "_comments` AS a
  133. INNER JOIN `" . NV_PREFIXLANG . "_" . $module_data . "` AS b ON a.fid = b.id
  134. LEFT JOIN `" . NV_USERS_GLOBALTABLE . "` as c ON a.post_id =c.userid
  135. WHERE a.fid=" . $id . " AND a.status=1 AND b.catid IN (" . $in . ") AND b.status=1 AND b.comment_allow=1
  136. ORDER BY a.post_time DESC LIMIT " . $page . "," . $per_page;
  137. $result = $db->sql_query( $query );
  138. $query = $db->sql_query( "SELECT FOUND_ROWS()" );
  139. list( $all_page ) = $db->sql_fetchrow( $query );
  140. if ( $all_page )
  141. {
  142. $base_url = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=getcomment&amp;list_comment=" . $id;
  143. $today = mktime( 0, 0, 0, date( "n" ), date( "j" ), date( "Y" ) );
  144. $yesterday = $today - 86400;
  145. while ( $row = $db->sql_fetchrow( $result ) )
  146. {
  147. $post_name = $row['post_name'];
  148. if ( ! $row['post_id'] )
  149. {
  150. $post_name .= " (" . nv_EncodeEmail( $row['post_email'] ) . ", " . $row['post_ip'] . ")";
  151. $row['photo'] = "";
  152. }
  153. else
  154. {
  155. $row['post_email'] = ( $row['view_mail'] ) ? $row['email'] : "";
  156. $row['post_name'] = $row['full_name'];
  157. if ( defined( 'NV_IS_MODADMIN' ) )
  158. {
  159. if ( isset( $users[$row['post_id']] ) )
  160. {
  161. $users[$row['post_id']][] = ( int )$row['id'];
  162. }
  163. else
  164. {
  165. $users[$row['post_id']] = array(
  166. $row['id']
  167. );
  168. }
  169. $post_name = "<a href=\"" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=users&amp;" . NV_OP_VARIABLE . "=edit&amp;userid=" . $row['post_id'] . "\">" . $post_name . "</a>";
  170. }
  171. }
  172. $post_time = ( int )$row['post_time'];
  173. if ( $post_time >= $today )
  174. {
  175. $post_time = $lang_module['today'] . ", " . date( "H:i", $post_time );
  176. }
  177. elseif ( $post_time >= $yesterday )
  178. {
  179. $post_time = $lang_module['yesterday'] . ", " . date( "H:i", $post_time );
  180. }
  181. else
  182. {
  183. $post_time = nv_date( "d/m/Y H:i", $post_time );
  184. }
  185. $admin_reply = "";
  186. if ( ! empty( $row['admin_id'] ) and ! empty( $row['admin_reply'] ) )
  187. {
  188. if ( defined( 'NV_IS_ADMIN' ) )
  189. {
  190. if ( isset( $admins[$row['admin_id']] ) )
  191. {
  192. $admins[$row['admin_id']][] = ( int )$row['id'];
  193. }
  194. else
  195. {
  196. $admins[$row['admin_id']] = array(
  197. $row['id']
  198. );
  199. }
  200. $admin_reply = $row['admin_reply'];
  201. }
  202. else
  203. {
  204. $admin_reply = $lang_module['comment_admin_note'] . ": " . $row['admin_reply'];
  205. }
  206. }
  207. $array[$row['id']] = array( //
  208. 'id' => ( int )$row['id'], //
  209. 'post_name' => $post_name, //
  210. 'post_email' => $row['post_email'], //
  211. 'photo' => $row['photo'], //
  212. 'post_ip' => $row['post_ip'], //
  213. 'post_time' => $post_time, //
  214. 'subject' => $row['subject'], //
  215. 'comment' => $row['comment'], //
  216. 'admin_reply' => $admin_reply, //
  217. 'edit_link' => NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=comment&amp;edit=1&amp;id=" . $row['id'], //
  218. 'del_link' => NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=comment"
  219. ); //
  220. }
  221. if ( ! empty( $users ) )
  222. {
  223. $in = array_keys( $users );
  224. $in = array_unique( $in );
  225. $in = implode( ",", $in );
  226. $query = "SELECT `view_mail`, `userid` FROM `" . NV_USERS_GLOBALTABLE . "` WHERE `userid` IN (" . $in . ")";
  227. $result = $db->sql_query( $query );
  228. while ( list( $view_mail, $userid ) = $db->sql_fetchrow( $result ) )
  229. {
  230. if ( isset( $users[$userid] ) )
  231. {
  232. foreach ( $users[$userid] as $id )
  233. {
  234. if ( ! empty( $array[$id]['post_email'] ) and ( defined( 'NV_IS_ADMIN' ) or $view_mail ) )
  235. {
  236. $array[$id]['post_email'] = nv_EncodeEmail( $array[$id]['post_email'] );
  237. $array[$id]['post_name'] .= " (" . $array[$id]['post_email'] . ", " . $array[$id]['post_ip'] . ")";
  238. }
  239. else
  240. {
  241. $array[$id]['post_email'] = "";
  242. }
  243. }
  244. }
  245. }
  246. }
  247. if ( ! empty( $admins ) )
  248. {
  249. $in = array_keys( $admins );
  250. $in = array_unique( $in );
  251. $in = implode( ",", $in );
  252. $query = "SELECT `userid` AS admin_id, `username` AS admin_login, `full_name` AS admin_name FROM `" . NV_USERS_GLOBALTABLE . "` WHERE `userid` IN (" . $in . ")";
  253. $result = $db->sql_query( $query );
  254. while ( list( $admin_id, $admin_login, $admin_name ) = $db->sql_fetchrow( $result ) )
  255. {
  256. $admin_name = ! empty( $admin_name ) ? $admin_name : $admin_login;
  257. if ( isset( $admins[$admin_id] ) )
  258. {
  259. foreach ( $admins[$admin_id] as $id )
  260. {
  261. $array[$id]['admin_reply'] = $lang_module['comment_admin_note'] . " <a href=\"" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=authors&amp;id=" . $admin_id . "\">" . $admin_name . "</a>: " . $array[$id]['admin_reply'];
  262. }
  263. }
  264. }
  265. }
  266. $generate_page = nv_generate_page( $base_url, $all_page, $per_page, $page, true, true, 'nv_urldecode_ajax', 'list_comments' );
  267. }
  268. $contents = show_comment( $array, $generate_page );
  269. die( $contents );
  270. }
  271. }
  272. die( $lang_module['comment_error7'] );
  273. }
  274. ?>