PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/NukeViet3.3/modules/users/admin/config.php

http://nuke-viet.googlecode.com/
PHP | 167 lines | 135 code | 26 blank | 6 comment | 13 complexity | e4773c4ea20e483103f20d930acae83b 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['config'];
  10. $array_config = array();
  11. function valid_name_config ( $array_name )
  12. {
  13. $array_retutn = array();
  14. foreach ( $array_name as $v )
  15. {
  16. $v = trim( $v );
  17. if ( ! empty( $v ) and preg_match( "/^[a-z0-9\-\.\_]+$/", $v ) )
  18. {
  19. $array_retutn[] = $v;
  20. }
  21. }
  22. return $array_retutn;
  23. }
  24. if ( $nv_Request->isset_request( 'submit', 'post' ) )
  25. {
  26. $array_config['allowmailchange'] = $nv_Request->get_int( 'allowmailchange', 'post', 0 );
  27. $array_config['allowuserpublic'] = $nv_Request->get_int( 'allowuserpublic', 'post', 0 );
  28. $array_config['allowquestion'] = $nv_Request->get_int( 'allowquestion', 'post', 0 );
  29. $array_config['allowloginchange'] = $nv_Request->get_int( 'allowloginchange', 'post', 0 );
  30. $array_config['allowuserlogin'] = $nv_Request->get_int( 'allowuserlogin', 'post', 0 );
  31. $array_config['allowuserreg'] = $nv_Request->get_int( 'allowuserreg', 'post', 0 );
  32. $array_config['openid_mode'] = $nv_Request->get_int( 'openid_mode', 'post', 0 );
  33. $array_config['is_user_forum'] = $nv_Request->get_int( 'is_user_forum', 'post', 0 );
  34. $array_config['openid_servers'] = $nv_Request->get_typed_array( 'openid_servers', 'post', 'string' );
  35. $array_config['openid_servers'] = ! empty( $array_config['openid_servers'] ) ? implode( ",", $array_config['openid_servers'] ) : "";
  36. foreach ( $array_config as $config_name => $config_value )
  37. {
  38. $query = "REPLACE INTO `" . NV_CONFIG_GLOBALTABLE . "` (`lang`, `module`, `config_name`, `config_value`) VALUES('sys', 'global', " . $db->dbescape( $config_name ) . ", " . $db->dbescape( $config_value ) . ")";
  39. $db->sql_query( $query );
  40. }
  41. $array_config['deny_email'] = filter_text_input( 'deny_email', 'post', '', 1 );
  42. if ( ! empty( $array_config['deny_email'] ) )
  43. {
  44. $array_config['deny_email'] = valid_name_config( explode( ",", $array_config['deny_email'] ) );
  45. $array_config['deny_email'] = implode( "|", $array_config['deny_email'] );
  46. }
  47. $sql = "UPDATE `" . NV_USERS_GLOBALTABLE . "_config` SET `content`=" . $db->dbescape( $array_config['deny_email'] ) . ", `edit_time`=" . NV_CURRENTTIME . " WHERE `config`='deny_email'";
  48. $db->sql_query( $sql );
  49. $array_config['deny_name'] = filter_text_input( 'deny_name', 'post', '', 1 );
  50. if ( ! empty( $array_config['deny_name'] ) )
  51. {
  52. $array_config['deny_name'] = valid_name_config( explode( ",", $array_config['deny_name'] ) );
  53. $array_config['deny_name'] = implode( "|", $array_config['deny_name'] );
  54. }
  55. $sql = "UPDATE `" . NV_USERS_GLOBALTABLE . "_config` SET `content`=" . $db->dbescape( $array_config['deny_name'] ) . ", `edit_time`=" . NV_CURRENTTIME . " WHERE `config`='deny_name'";
  56. $db->sql_query( $sql );
  57. nv_save_file_config_global();
  58. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&rand=" . nv_genpass() );
  59. die();
  60. }
  61. $array_config = array();
  62. $sql = "SELECT `config_name`, `config_value` FROM `" . NV_CONFIG_GLOBALTABLE . "` WHERE `lang`='sys' AND `module`='global' AND
  63. `config_name` IN ('allowmailchange','allowuserpublic','allowquestion','allowuserreg','allowloginchange','allowuserlogin','openid_mode','is_user_forum','openid_servers')";
  64. $result = $db->sql_query( $sql );
  65. while ( list( $c_config_name, $c_config_value ) = $db->sql_fetchrow( $result ) )
  66. {
  67. $array_config[$c_config_name] = $c_config_value;
  68. }
  69. $array_config['allowmailchange'] = ! empty( $array_config['allowmailchange'] ) ? " checked=\"checked\"" : "";
  70. $array_config['allowuserpublic'] = ! empty( $array_config['allowuserpublic'] ) ? " checked=\"checked\"" : "";
  71. $array_config['allowquestion'] = ! empty( $array_config['allowquestion'] ) ? " checked=\"checked\"" : "";
  72. $array_config['allowloginchange'] = ! empty( $array_config['allowloginchange'] ) ? " checked=\"checked\"" : "";
  73. $array_config['allowuserlogin'] = ! empty( $array_config['allowuserlogin'] ) ? " checked=\"checked\"" : "";
  74. $array_config['openid_mode'] = ! empty( $array_config['openid_mode'] ) ? " checked=\"checked\"" : "";
  75. $array_config['is_user_forum'] = ! empty( $array_config['is_user_forum'] ) ? " checked=\"checked\"" : "";
  76. $servers = $array_config['openid_servers'];
  77. $servers = ! empty( $servers ) ? explode( ",", $servers ) : array();
  78. $openid_servers = array();
  79. include ( NV_ROOTDIR . '/includes/openid.php' );
  80. $array_config['openid_servers'] = array();
  81. if ( ! empty( $openid_servers ) )
  82. {
  83. $array_keys = array_keys( $openid_servers );
  84. foreach ( $array_keys as $server )
  85. {
  86. $checked = ( ! empty( $servers ) and in_array( $server, $servers ) ) ? " checked=\"checked\"" : "";
  87. $array_config['openid_servers'][] = array(
  88. 'name' => $server, 'checked' => $checked
  89. );
  90. }
  91. }
  92. $sql = "SELECT `config`, `content` FROM `" . NV_USERS_GLOBALTABLE . "_config` WHERE `config`='deny_email' OR `config`='deny_name'";
  93. $result = $db->sql_query( $sql );
  94. while ( list( $config, $content ) = $db->sql_fetchrow( $result ) )
  95. {
  96. if ( ! empty( $content ) )
  97. {
  98. $content = array_map( "trim", explode( "|", $content ) );
  99. $content = implode( ", ", $content );
  100. }
  101. $array_config[$config] = $content;
  102. }
  103. $db->sql_freeresult();
  104. $array_registertype = array(
  105. 0 => $lang_module['active_not_allow'], 1 => $lang_module['active_all'], 2 => $lang_module['active_email'], 3 => $lang_module['active_admin_check']
  106. );
  107. $xtpl = new XTemplate( "config.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  108. $xtpl->assign( 'FORM_ACTION', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $op );
  109. $xtpl->assign( 'LANG', $lang_module );
  110. $xtpl->assign( 'DATA', $array_config );
  111. if ( file_exists( NV_ROOTDIR . '/' . DIR_FORUM . '/nukeviet' ) )
  112. {
  113. $forum_files = @scandir( NV_ROOTDIR . '/' . DIR_FORUM . '/nukeviet' );
  114. if ( ! empty( $forum_files ) and in_array( 'is_user.php', $forum_files ) and in_array( 'changepass.php', $forum_files ) and in_array( 'editinfo.php', $forum_files ) and in_array( 'login.php', $forum_files ) and in_array( 'logout.php', $forum_files ) and in_array( 'lostpass.php', $forum_files ) and in_array( 'register.php', $forum_files ) )
  115. {
  116. $xtpl->parse( 'main.user_forum' );
  117. }
  118. }
  119. foreach ( $array_registertype as $id => $titleregister )
  120. {
  121. $select = ( $array_config['allowuserreg'] == $id ) ? " selected=\"selected\"" : "";
  122. $array = array(
  123. "id" => $id, "select" => $select, "value" => $titleregister
  124. );
  125. $xtpl->assign( 'REGISTERTYPE', $array );
  126. $xtpl->parse( 'main.registertype' );
  127. }
  128. if ( ! empty( $array_config['openid_servers'] ) )
  129. {
  130. foreach ( $array_config['openid_servers'] as $server )
  131. {
  132. $xtpl->assign( 'OPENID', $server );
  133. $xtpl->parse( 'main.openid_servers' );
  134. }
  135. }
  136. $xtpl->parse( 'main' );
  137. $contents = $xtpl->text( 'main' );
  138. include ( NV_ROOTDIR . "/includes/header.php" );
  139. echo nv_admin_theme( $contents );
  140. include ( NV_ROOTDIR . "/includes/footer.php" );
  141. ?>