PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/NukeViet3.2/modules/users/admin/user_add.php

http://nuke-viet.googlecode.com/
PHP | 275 lines | 234 code | 35 blank | 6 comment | 31 complexity | 82fc2800dbaae5b2b3f54b28f7021ad5 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * @Project NUKEVIET CMS 3.0
  4. * @Author VINADES (contact@vinades.vn)
  5. * @Copyright (C) 2010 VINADES. All rights reserved
  6. * @Createdate 04/05/2010
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. $page_title = $lang_module['user_add'];
  10. $groups_list = nv_groups_list();
  11. $_user = array();
  12. $error = "";
  13. if ( $nv_Request->isset_request( 'confirm', 'post' ) )
  14. {
  15. $_user['username'] = filter_text_input( 'username', 'post', '', 1, NV_UNICKMAX );
  16. $_user['email'] = filter_text_input( 'email', 'post', '', 1, 100 );
  17. $_user['password1'] = filter_text_input( 'password1', 'post', '', 0, NV_UPASSMAX );
  18. $_user['password2'] = filter_text_input( 'password2', 'post', '', 0, NV_UPASSMAX );
  19. $_user['question'] = filter_text_input( 'question', 'post', '', 1, 255 );
  20. $_user['answer'] = filter_text_input( 'answer', 'post', '', 1, 255 );
  21. $_user['full_name'] = filter_text_input( 'full_name', 'post', '', 1, 255 );
  22. $_user['gender'] = filter_text_input( 'gender', 'post', '', 1, 1 );
  23. $_user['website'] = filter_text_input( 'website', 'post', '' );
  24. $_user['location'] = filter_text_input( 'location', 'post', '', 1 );
  25. $_user['yim'] = filter_text_input( 'yim', 'post', '', 1, 100 );
  26. $_user['telephone'] = filter_text_input( 'telephone', 'post', '', 1, 100 );
  27. $_user['fax'] = filter_text_input( 'fax', 'post', '', 1, 100 );
  28. $_user['mobile'] = filter_text_input( 'mobile', 'post', '', 1, 100 );
  29. $_user['view_mail'] = $nv_Request->get_int( 'view_mail', 'post', 0 );
  30. $_user['sig'] = filter_text_textarea( 'sig', '', NV_ALLOWED_HTML_TAGS );
  31. $_user['birthday'] = filter_text_input( 'birthday', 'post', '', 1, 10 );
  32. $_user['in_groups'] = $nv_Request->get_typed_array( 'group', 'post', 'int' );
  33. if ( ! empty( $_user['website'] ) )
  34. {
  35. if ( ! preg_match( "#^(http|https|ftp|gopher)\:\/\/#", $_user['website'] ) )
  36. {
  37. $_user['website'] = "http://" . $_user['website'];
  38. }
  39. if ( ! nv_is_url( $_user['website'] ) )
  40. {
  41. $_user['website'] = "";
  42. }
  43. }
  44. if ( ( $error_username = nv_check_valid_login( $_user['username'], NV_UNICKMAX, NV_UNICKMIN ) ) != "" )
  45. {
  46. $error = $error_username;
  47. }
  48. elseif ( $_user['username'] != $db->fixdb( $_user['username'] ) )
  49. {
  50. $error = sprintf( $lang_module['account_deny_name'], '<strong>' . $_user['username'] . '</strong>' );
  51. }
  52. elseif ( ( $error_xemail = nv_check_valid_email( $_user['email'] ) ) != "" )
  53. {
  54. $error = $error_xemail;
  55. }
  56. elseif ( $db->sql_numrows( $db->sql_query( "SELECT `userid` FROM `" . NV_USERS_GLOBALTABLE . "` WHERE `md5username`=" . $db->dbescape( md5( $_user['username'] ) ) ) ) != 0 )
  57. {
  58. $error = $lang_module['edit_error_username_exist'];
  59. }
  60. elseif ( $db->sql_numrows( $db->sql_query( "SELECT `userid` FROM `" . NV_USERS_GLOBALTABLE . "` WHERE `email`=" . $db->dbescape( $_user['email'] ) ) ) != 0 )
  61. {
  62. $error = $lang_module['edit_error_email_exist'];
  63. }
  64. elseif ( $db->sql_numrows( $db->sql_query( "SELECT `userid` FROM `" . NV_USERS_GLOBALTABLE . "_reg` WHERE `email`=" . $db->dbescape( $_user['email'] ) ) ) != 0 )
  65. {
  66. $error = $lang_module['edit_error_email_exist'];
  67. }
  68. elseif ( $db->sql_numrows( $db->sql_query( "SELECT `userid` FROM `" . NV_USERS_GLOBALTABLE . "_openid` WHERE `email`=" . $db->dbescape( $_user['email'] ) ) ) != 0 )
  69. {
  70. $error = $lang_module['edit_error_email_exist'];
  71. }
  72. elseif ( ( $check_pass = nv_check_valid_pass( $_user['password1'], NV_UPASSMAX, NV_UPASSMIN ) ) != "" )
  73. {
  74. $error = $check_pass;
  75. }
  76. elseif ( $_user['password1'] != $_user['password2'] )
  77. {
  78. $error = $lang_module['edit_error_password'];
  79. }
  80. elseif ( empty( $_user['question'] ) )
  81. {
  82. $error = $lang_module['edit_error_question'];
  83. }
  84. elseif ( empty( $_user['answer'] ) )
  85. {
  86. $error = $lang_module['edit_error_answer'];
  87. }
  88. else
  89. {
  90. $_user['sig'] = nv_nl2br( $_user['sig'], "<br />" );
  91. if ( $_user['gender'] != "M" and $_user['gender'] != "F" )
  92. {
  93. $_user['gender'] = "";
  94. }
  95. unset( $m );
  96. if ( preg_match( "/^([0-9]{1,2})\.([0-9]{1,2})\.([0-9]{4})$/", $_user['birthday'], $m ) )
  97. {
  98. $_user['birthday'] = mktime( 0, 0, 0, $m[2], $m[1], $m[3] );
  99. }
  100. else
  101. {
  102. $_user['birthday'] = 0;
  103. }
  104. $data_in_groups = ( ! empty( $_user['in_groups'] ) ) ? implode( ',', $_user['in_groups'] ) : '';
  105. $password = $crypt->hash( $_user['password1'] );
  106. $sql = "INSERT INTO `" . NV_USERS_GLOBALTABLE . "` (
  107. `userid`, `username`, `md5username`, `password`, `email`, `full_name`, `gender`, `birthday`, `sig`, `regdate`,
  108. `website`, `location`, `yim`, `telephone`, `fax`, `mobile`, `question`, `answer`, `passlostkey`, `view_mail`,
  109. `remember`, `in_groups`, `active`, `checknum`, `last_login`, `last_ip`, `last_agent`, `last_openid`)
  110. VALUES(
  111. NULL,
  112. " . $db->dbescape( $_user['username'] ) . ",
  113. " . $db->dbescape( md5( $_user['username'] ) ) . ",
  114. " . $db->dbescape( $password ) . ",
  115. " . $db->dbescape( $_user['email'] ) . ",
  116. " . $db->dbescape( $_user['full_name'] ) . ",
  117. " . $db->dbescape( $_user['gender'] ) . ",
  118. " . $_user['birthday'] . ",
  119. " . $db->dbescape( $_user['sig'] ) . ",
  120. " . NV_CURRENTTIME . ",
  121. " . $db->dbescape( $_user['website'] ) . ",
  122. " . $db->dbescape( $_user['location'] ) . ",
  123. " . $db->dbescape( $_user['yim'] ) . ",
  124. " . $db->dbescape( $_user['telephone'] ) . ",
  125. " . $db->dbescape( $_user['fax'] ) . ",
  126. " . $db->dbescape( $_user['mobile'] ) . ",
  127. " . $db->dbescape( $_user['question'] ) . ",
  128. " . $db->dbescape( $_user['answer'] ) . ",
  129. '',
  130. " . $_user['view_mail'] . ",
  131. 1,
  132. " . $db->dbescape_string( $data_in_groups ) . ",
  133. 1, '', 0, '', '', '')";
  134. $userid = $db->sql_query_insert_id( $sql );
  135. if ( $userid )
  136. {
  137. nv_insert_logs( NV_LANG_DATA, $module_name, 'log_add_user', "userid " . $userid, $admin_info['userid'] );
  138. if ( isset( $_FILES['photo'] ) and is_uploaded_file( $_FILES['photo']['tmp_name'] ) )
  139. {
  140. @require_once ( NV_ROOTDIR . "/includes/class/upload.class.php" );
  141. $upload = new upload( array( 'images' ), $global_config['forbid_extensions'], $global_config['forbid_mimes'], NV_UPLOAD_MAX_FILESIZE, 80, 80 );
  142. $upload_info = $upload->save_file( $_FILES['photo'], NV_UPLOADS_REAL_DIR . '/' . $module_name, false );
  143. @unlink( $_FILES['photo']['tmp_name'] );
  144. if ( empty( $upload_info['error'] ) )
  145. {
  146. @chmod( $upload_info['name'], 0644 );
  147. $file_name = str_replace( NV_ROOTDIR . "/", "", $upload_info['name'] );
  148. $sql = "UPDATE `" . NV_USERS_GLOBALTABLE . "` SET `photo`=" . $db->dbescape( $file_name ) . " WHERE `userid`=" . $userid;
  149. $db->sql_query( $sql );
  150. }
  151. }
  152. if ( ! empty( $_user['in_groups'] ) )
  153. {
  154. foreach ( $_user['in_groups'] as $group_id_i )
  155. {
  156. $query = "SELECT `users` FROM `" . NV_GROUPS_GLOBALTABLE . "` WHERE `group_id`=" . $group_id_i;
  157. $result = $db->sql_query( $query );
  158. $numrows = $db->sql_numrows( $result );
  159. if ( $numrows )
  160. {
  161. $row_users = $db->sql_fetchrow( $result );
  162. $users = trim( $row_users['users'] );
  163. $users = ! empty( $users ) ? explode( ",", $users ) : array();
  164. $users = array_merge( $users, array( $userid ) );
  165. $users = array_unique( $users );
  166. sort( $users );
  167. $users = array_values( $users );
  168. $users = ! empty( $users ) ? implode( ",", $users ) : "";
  169. $sql = "UPDATE `" . NV_GROUPS_GLOBALTABLE . "` SET `users`=" . $db->dbescape_string( $users ) . " WHERE `group_id`=" . $group_id_i;
  170. $db->sql_query( $sql );
  171. }
  172. }
  173. }
  174. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name );
  175. exit();
  176. }
  177. $error = $lang_module['edit_add_error'];
  178. }
  179. }
  180. else
  181. {
  182. $_user['username'] = $_user['email'] = $_user['password1'] = $_user['password2'] = $_user['question'] = $_user['answer'] = "";
  183. $_user['full_name'] = $_user['gender'] = $_user['website'] = $_user['location'] = $_user['yim'] = $_user['telephone'] = "";
  184. $_user['fax'] = $_user['mobile'] = $_user['sig'] = $_user['birthday'] = "";
  185. $_user['view_mail'] = 0;
  186. $_user['in_groups'] = array();
  187. }
  188. $genders = array( //
  189. 'N' => array( 'key' => 'N', 'title' => $lang_module['NA'], 'selected' => '' ), //
  190. 'M' => array( 'key' => 'M', 'title' => $lang_module['male'], 'selected' => $_user['gender'] == "M" ? " selected=\"selected\"" : "" ), //
  191. 'F' => array( 'key' => 'F', 'title' => $lang_module['female'], 'selected' => $_user['gender'] == "F" ? " selected=\"selected\"" : "" ) );//
  192. $_user['view_mail'] = $_user['view_mail'] ? " checked=\"checked\"" : "";
  193. if ( ! empty( $_user['sig'] ) ) $_user['sig'] = nv_htmlspecialchars( $_user['sig'] );
  194. $groups = array();
  195. if ( ! empty( $groups_list ) )
  196. {
  197. foreach ( $groups_list as $group_id => $grtl )
  198. {
  199. $groups[] = array( 'id' => $group_id, 'title' => $grtl, 'checked' => ( ! empty( $_user['in_groups'] ) and in_array( $group_id, $_user['in_groups'] ) ) ? " checked=\"checked\"" : "" );
  200. }
  201. }
  202. $xtpl = new XTemplate( "user_add.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  203. $xtpl->assign( 'LANG', $lang_module );
  204. $xtpl->assign( 'DATA', $_user );
  205. $xtpl->assign( 'FORM_ACTION', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=user_add" );
  206. $xtpl->assign( 'NV_BASE_SITEURL', NV_BASE_SITEURL );
  207. if ( ! empty( $error ) )
  208. {
  209. $xtpl->assign( 'ERROR', $error );
  210. $xtpl->parse( 'main.error' );
  211. }
  212. if ( defined( 'NV_IS_USER_FORUM' ) )
  213. {
  214. $xtpl->parse( 'main.is_forum' );
  215. }
  216. else
  217. {
  218. foreach ( $genders as $gender )
  219. {
  220. $xtpl->assign( 'GENDER', $gender );
  221. $xtpl->parse( 'main.add_user.gender' );
  222. }
  223. if ( ! empty( $groups ) )
  224. {
  225. foreach ( $groups as $group )
  226. {
  227. $xtpl->assign( 'GROUP', $group );
  228. $xtpl->parse( 'main.add_user.group.list' );
  229. }
  230. $xtpl->parse( 'main.add_user.group' );
  231. }
  232. $xtpl->parse( 'main.add_user' );
  233. }
  234. $xtpl->parse( 'main' );
  235. $contents = $xtpl->text( 'main' );
  236. $my_head = "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "js/popcalendar/popcalendar.js\"></script>\n";
  237. include ( NV_ROOTDIR . "/includes/header.php" );
  238. echo nv_admin_theme( $contents );
  239. include ( NV_ROOTDIR . "/includes/footer.php" );
  240. ?>