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

/nukeviet/modules/contact/funcs/main.php

http://nuke-viet.googlecode.com/
PHP | 226 lines | 171 code | 38 blank | 17 comment | 18 complexity | 1c0170252bdb176b0e81d05165af5ad6 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET 3.x
  4. * @Author VINADES (contact@vinades.vn)
  5. * @Copyright (C) 2012 VINADES. All rights reserved
  6. * @Createdate Apr 20, 2010 10:47:41 AM
  7. */
  8. if( ! defined( 'NV_IS_MOD_CONTACT' ) ) die( 'Stop!!!' );
  9. /**
  10. * nv_SendMail2User()
  11. *
  12. * @param mixed $cid
  13. * @param mixed $fcontent
  14. * @param mixed $ftitle
  15. * @param mixed $femail
  16. * @param mixed $full_name
  17. * @return void
  18. */
  19. function nv_SendMail2User( $cid, $fcontent, $ftitle, $femail, $full_name )
  20. {
  21. global $db, $module_data;
  22. $email_list = array();
  23. $sql = "SELECT `email`, `admins` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_rows` WHERE `id` =" . $cid;
  24. $result = $db->sql_query( $sql );
  25. list( $email, $admins ) = $db->sql_fetchrow( $result );
  26. if( ! empty( $email ) )
  27. {
  28. $email_list[] = $email;
  29. }
  30. if( ! empty( $admins ) )
  31. {
  32. $admins = array_map( "trim", explode( ";", $admins ) );
  33. $a_l = array();
  34. foreach( $admins as $adm )
  35. {
  36. if( preg_match( "/^([0-9]+)\/([0-1]{1})\/([0-1]{1})\/([0-1]{1})$/i", $adm ) )
  37. {
  38. $adm2 = array_map( "trim", explode( "/", $adm ) );
  39. if( $adm2[3] == 1 )
  40. {
  41. $a_l[] = intval( $adm2[0] );
  42. }
  43. }
  44. }
  45. if( ! empty( $a_l ) )
  46. {
  47. $a_l = implode( ",", $a_l );
  48. $sql = "SELECT t2.email as admin_email FROM `" . NV_AUTHORS_GLOBALTABLE . "` AS t1 INNER JOIN `" . NV_USERS_GLOBALTABLE . "` AS t2 ON t1.admin_id = t2.userid WHERE t1.lev!=0 AND t1.is_suspend=0 AND t1.admin_id IN (" . $a_l . ")";
  49. $result = $db->sql_query( $sql );
  50. while( $row = $db->sql_fetchrow( $result ) )
  51. {
  52. if( nv_check_valid_email( $row['admin_email'] ) == "" )
  53. {
  54. $email_list[] = $row['admin_email'];
  55. }
  56. }
  57. }
  58. }
  59. $email_list = array_unique( $email_list );
  60. if( ! empty( $email_list ) )
  61. {
  62. $from = array( $full_name, $femail );
  63. foreach( $email_list as $to )
  64. {
  65. @nv_sendmail( $from, $to, $ftitle, $fcontent );
  66. }
  67. }
  68. }
  69. //Danh sach cac bo phan
  70. $sql = "SELECT `id`, `full_name`, `phone`, `fax`, `email`, `note` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_rows` WHERE `act`=1";
  71. $array_rows = nv_db_cache( $sql, 'id' );
  72. $page_title = $module_info['custom_title'];
  73. $key_words = $module_info['keywords'];
  74. $mod_title = isset( $lang_module['main_title'] ) ? $lang_module['main_title'] : $module_info['custom_title'];
  75. $fname = "";
  76. $femail = "";
  77. $fphone = "";
  78. if( defined( 'NV_IS_USER' ) )
  79. {
  80. $fname = ! empty( $user_info['full_name'] ) ? $user_info['full_name'] : $user_info['username'];
  81. $femail = $user_info['email'];
  82. $fphone = $user_info['telephone'];
  83. }
  84. $fcon = "";
  85. $fcode = "";
  86. $error = "";
  87. $fpart = isset( $array_op[0] ) ? $array_op[0] : 0;
  88. $fpart = $nv_Request->get_int( 'fpart', 'post,get', $fpart );
  89. $ftitle = filter_text_input( 'ftitle', 'post,get', '', 1, 250 );
  90. if( ! empty( $array_rows ) )
  91. {
  92. $checkss = filter_text_input( 'checkss', 'post', '' );
  93. if( $checkss == md5( $client_info['session_id'] . $global_config['sitekey'] ) )
  94. {
  95. if( defined( 'NV_IS_USER' ) )
  96. {
  97. $fname = ! empty( $user_info['full_name'] ) ? $user_info['full_name'] : $user_info['username'];
  98. $femail = $user_info['email'];
  99. }
  100. else
  101. {
  102. $fname = filter_text_input( 'fname', 'post', '', 1, 100 );
  103. $femail = filter_text_input( 'femail', 'post', '', 1, 100 );
  104. }
  105. $fphone = filter_text_input( 'fphone', 'post', '', 1, 100 );
  106. $fcon = filter_text_textarea( 'fcon', '', NV_ALLOWED_HTML_TAGS );
  107. $fcode = filter_text_input( 'fcode', 'post', '' );
  108. $check_valid_email = nv_check_valid_email( $femail );
  109. if( empty( $fname ) )
  110. {
  111. $error = $lang_module['error_fullname'];
  112. }
  113. elseif( ! empty( $check_valid_email ) )
  114. {
  115. $error = $check_valid_email;
  116. }
  117. elseif( empty( $ftitle ) )
  118. {
  119. $error = $lang_module['error_title'];
  120. }
  121. elseif( empty( $fcon ) )
  122. {
  123. $error = $lang_module['error_content'];
  124. }
  125. elseif( ! isset( $array_rows[$fpart] ) )
  126. {
  127. $error = $lang_module['error_part'];
  128. }
  129. elseif( ! nv_capcha_txt( $fcode ) )
  130. {
  131. $error = $lang_module['error_captcha'];
  132. }
  133. else
  134. {
  135. $fcon = nv_nl2br( $fcon );
  136. $sender_id = intval( defined( 'NV_IS_USER' ) ? $user_info['userid'] : 0 );
  137. $sql = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_send` VALUES
  138. (NULL , " . $fpart . ", " . $db->dbescape( $ftitle ) . ", " . $db->dbescape( $fcon ) . ",
  139. " . NV_CURRENTTIME . ", " . $sender_id . ", " . $db->dbescape( $fname ) . ", " . $db->dbescape( $femail ) . ",
  140. " . $db->dbescape( $fphone ) . ", " . $db->dbescape( $client_info['ip'] ) . ", 0, 0, '', 0, 0);";
  141. $db->sql_query( $sql );
  142. $website = "<a href=\"" . $global_config['site_url'] . "\">" . $global_config['site_name'] . "</a>";
  143. $fcon .= "<br /><br />----------------------------------------<br /><br />";
  144. if( empty( $fphone ) )
  145. {
  146. $fcon .= sprintf( $lang_module['sendinfo'], $website, $fname, $femail, $client_info['ip'], $array_rows[$fpart]['full_name'] );
  147. }
  148. else
  149. {
  150. $fcon .= sprintf( $lang_module['sendinfo2'], $website, $fname, $femail, $fphone, $client_info['ip'], $array_rows[$fpart]['full_name'] );
  151. }
  152. nv_SendMail2User( $fpart, $fcon, $ftitle, $femail, $fname );
  153. $url = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA;
  154. $contents .= call_user_func( "sendcontact", $url );
  155. include ( NV_ROOTDIR . "/includes/header.php" );
  156. echo nv_site_theme( $contents );
  157. include ( NV_ROOTDIR . "/includes/footer.php" );
  158. exit();
  159. }
  160. }
  161. }
  162. $bodytext = "";
  163. $content_file = NV_ROOTDIR . '/' . NV_DATADIR . '/' . NV_LANG_DATA . '_' . $module_data . 'Content.txt';
  164. if( isset( $array_rows[$fpart] ) and ! empty( $array_rows[$fpart]['note'] ) )
  165. {
  166. $bodytext = $array_rows[$fpart]['note'];
  167. }
  168. elseif( file_exists( $content_file ) )
  169. {
  170. $bodytext = file_get_contents( $content_file );
  171. }
  172. $array_content = array( //
  173. "error" => $error, //
  174. "fpart" => $fpart, //
  175. "bodytext" => $bodytext, //
  176. "fname" => $fname, //
  177. "femail" => $femail, //
  178. "fcon" => $fcon, //
  179. "ftitle" => $ftitle, //
  180. 'fphone' => $fphone //
  181. );
  182. $checkss = md5( $client_info['session_id'] . $global_config['sitekey'] );
  183. $base_url = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module_name;
  184. $contents = call_user_func( "main_theme", $array_content, $array_rows, $base_url, $checkss );
  185. include ( NV_ROOTDIR . "/includes/header.php" );
  186. echo nv_site_theme( $contents );
  187. include ( NV_ROOTDIR . "/includes/footer.php" );
  188. ?>