PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/nukeviet/admin/modules/language/main.php

http://nuke-viet.googlecode.com/
PHP | 332 lines | 254 code | 64 blank | 14 comment | 26 complexity | 47ec3d45bb1c4cd1f20a265f235942cd 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.,JSC (contact@vinades.vn)
  5. * @Copyright (C) 2012 VINADES.,JSC. All rights reserved
  6. * @Createdate 2-2-2010 12:55
  7. */
  8. if( ! defined( 'NV_IS_FILE_LANG' ) ) die( 'Stop!!!' );
  9. $page_title = $lang_module['nv_lang_data'];
  10. $xtpl = new XTemplate( "main.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  11. $xtpl->assign( 'LANG', $lang_module );
  12. $xtpl->assign( 'GLANG', $lang_global );
  13. $sql = "SELECT `lang`, `setup` FROM `" . $db_config['prefix'] . "_setup_language`";
  14. $result = $db->sql_query( $sql );
  15. $array_lang_setup = array();
  16. while( $row = $db->sql_fetchrow( $result ) )
  17. {
  18. $array_lang_setup[$row['lang']] = intval( $row['setup'] );
  19. }
  20. $checksess = filter_text_input( 'checksess', 'get', '' );
  21. $keylang = filter_text_input( 'keylang', 'get', '', 1, 2 );
  22. $deletekeylang = filter_text_input( 'deletekeylang', 'get', '', 1, 2 );
  23. if( $nv_Request->isset_request( 'activelang', 'get' ) and $checksess == md5( "activelang_" . $keylang . session_id() ) )
  24. {
  25. $activelang = $nv_Request->get_int( 'activelang', 'get', 0 );
  26. $allow_sitelangs = $global_config['allow_sitelangs'];
  27. if( $activelang )
  28. {
  29. $allow_sitelangs[] = $keylang;
  30. }
  31. elseif( $keylang != $global_config['site_lang'] )
  32. {
  33. $allow_sitelangs = array_diff( $allow_sitelangs, array( $keylang ) );
  34. }
  35. $allow_sitelangs = array_unique( $allow_sitelangs );
  36. $query = "UPDATE `" . NV_CONFIG_GLOBALTABLE . "` SET `config_value` = " . $db->dbescape( implode( ",", $allow_sitelangs ) ) . " WHERE `lang`='sys' AND `module` = 'global' AND `config_name` = 'allow_sitelangs'";
  37. $result = $db->sql_query( $query );
  38. $temp = ( $activelang == 1 ) ? $lang_global['yes'] : $lang_global['no'];
  39. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['nv_lang_slsite'], " langkey : " . $keylang . " [ " . $temp . " ]", $admin_info['userid'] );
  40. nv_save_file_config_global();
  41. $xtpl->assign( 'URL', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op );
  42. $xtpl->parse( 'activelang' );
  43. $contents = $xtpl->text( 'activelang' );
  44. include ( NV_ROOTDIR . "/includes/header.php" );
  45. echo nv_admin_theme( $contents );
  46. include ( NV_ROOTDIR . "/includes/footer.php" );
  47. exit();
  48. }
  49. elseif( $checksess == md5( $keylang . session_id() ) and in_array( $keylang, $global_config['allow_adminlangs'] ) )
  50. {
  51. if( isset( $array_lang_setup[$keylang] ) and $array_lang_setup[$keylang] == 1 )
  52. {
  53. info_die( $lang_module['nv_data_setup'] );
  54. }
  55. else
  56. {
  57. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['nv_setup_new'] . " " . $lang_module['nv_lang_data'], " langkey : " . $keylang, $admin_info['userid'] );
  58. list( $site_theme ) = $db->sql_fetchrow( $db->sql_query( "SELECT `config_value` FROM `" . NV_CONFIG_GLOBALTABLE . "` where `lang`='" . $global_config['site_lang'] . "' AND `module`='global' AND `config_name`='site_theme'" ) );
  59. $global_config['site_theme'] = $site_theme;
  60. require_once ( NV_ROOTDIR . '/includes/sqldata.php' );
  61. $sql_create_table = nv_create_table_sys( $keylang );
  62. foreach( $sql_create_table as $query )
  63. {
  64. $db->sql_query( $query );
  65. }
  66. $db->sql_query( "REPLACE INTO `" . $db_config['prefix'] . "_setup_language` (`lang`, `setup`) VALUES ('" . $keylang . "', '1')" );
  67. $db->sql_query( "UPDATE `" . $db_config['prefix'] . "_" . $keylang . "_modules` SET `act` = '0'" );
  68. if( defined( 'NV_MODULE_SETUP_DEFAULT' ) )
  69. {
  70. $lang_module['modules'] = "";
  71. $lang_module['vmodule_add'] = "";
  72. $lang_module['blocks'] = "";
  73. $lang_module['autoinstall'] = "";
  74. $lang_global['mod_modules'] = "";
  75. $module_name = "modules";
  76. require_once ( NV_ROOTDIR . "/" . NV_ADMINDIR . "/modules/modules/functions.php" );
  77. $module_name = "";
  78. $array_module_setup = explode( ",", NV_MODULE_SETUP_DEFAULT );
  79. $modules_exit = nv_scandir( NV_ROOTDIR . "/modules", $global_config['check_module'] );
  80. $modules_exit[] = 'global';
  81. foreach( $array_module_setup as $setmodule )
  82. {
  83. if( in_array( $setmodule, $modules_exit ) )
  84. {
  85. $sm = nv_setup_data_module( $keylang, $setmodule );
  86. if( $sm == "OK_" . $setmodule )
  87. {
  88. $db->sql_query( "UPDATE `" . $db_config['prefix'] . "_" . $keylang . "_modules` SET `act` = '1'WHERE `title`='" . $setmodule . "'" );
  89. }
  90. }
  91. }
  92. $db->sql_query( "DELETE FROM `" . $db_config['prefix'] . "_" . $keylang . "_modules` WHERE `act` = '0'" );
  93. //cai dat du lieu mau
  94. $filesavedata = "";
  95. $lang_data = $keylang;
  96. if( file_exists( NV_ROOTDIR . "/install/data_" . $keylang . ".php" ) )
  97. {
  98. $filesavedata = $keylang;
  99. }
  100. elseif( file_exists( NV_ROOTDIR . "/install/data_en.php" ) )
  101. {
  102. $filesavedata = "en";
  103. }
  104. if( ! empty( $filesavedata ) )
  105. {
  106. $sql_create_table = array();
  107. include_once ( NV_ROOTDIR . "/install/data_" . $filesavedata . ".php" );
  108. foreach( $sql_create_table as $query )
  109. {
  110. if( ! $db->sql_query( $query ) )
  111. {
  112. include ( NV_ROOTDIR . "/includes/header.php" );
  113. echo nv_admin_theme( "ERROR SETUP SQL: <br />" . $query );
  114. include ( NV_ROOTDIR . "/includes/footer.php" );
  115. exit();
  116. }
  117. }
  118. //xoa du lieu tai bang nv3_vi_blocks
  119. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang_data . "_blocks_weight` WHERE `bid` in (SELECT `bid` FROM `" . $db_config['prefix'] . "_" . $lang_data . "_blocks_groups` WHERE `module` NOT IN ('" . implode( "', '", $modules_exit ) . "'))";
  120. $db->sql_query( $sql );
  121. //xoa du lieu tai bang nv3_vi_blocks_groups
  122. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang_data . "_blocks_groups` WHERE `module` NOT IN ('" . implode( "', '", $modules_exit ) . "')";
  123. $db->sql_query( $sql );
  124. //xoa du lieu tai bang nv3_vi_modthemes
  125. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang_data . "_modthemes` WHERE `func_id` in (SELECT `func_id` FROM `" . $db_config['prefix'] . "_" . $lang_data . "_modfuncs` WHERE `in_module` NOT IN ('" . implode( "', '", $modules_exit ) . "'))";
  126. $db->sql_query( $sql );
  127. //xoa du lieu tai bang nv3_vi_modfuncs
  128. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang_data . "_modfuncs` WHERE `in_module` NOT IN ('" . implode( "', '", $modules_exit ) . "')";
  129. $db->sql_query( $sql );
  130. //xoa du lieu tai bang nv3_vi_modules
  131. $sql = "DELETE FROM `" . $db_config['prefix'] . "_" . $lang_data . "_modules` WHERE `title` NOT IN ('" . implode( "', '", $modules_exit ) . "')";
  132. $db->sql_query( $sql );
  133. //xoa du lieu tai bang nv3_setup_modules
  134. $sql = "DELETE FROM `" . $db_config['prefix'] . "_setup_modules` WHERE `title` NOT IN ('" . implode( "', '", $modules_exit ) . "')";
  135. $db->sql_query( $sql );
  136. ///xoa du lieu tai bang nv3_config
  137. $sql = "DELETE FROM `" . $db_config['prefix'] . "_config` WHERE `lang`=" . $db->dbescape( $lang_data ) . " AND `module` NOT IN ('" . implode( "', '", $modules_exit ) . "')";
  138. $db->sql_query( $sql );
  139. $sql = "SELECT * FROM `" . $db_config['prefix'] . "_" . $lang_data . "_modules` WHERE `title`='news'";
  140. $result = $db->sql_query( $sql );
  141. if( $db->sql_numrows( $result ) )
  142. {
  143. $result = $db->sql_query( "SELECT catid FROM `" . $db_config['prefix'] . "_" . $lang_data . "_news_cat` ORDER BY `order` ASC" );
  144. while( list( $catid_i ) = $db->sql_fetchrow( $result ) )
  145. {
  146. nv_create_table_news( $catid_i );
  147. }
  148. $db->sql_freeresult();
  149. $result = $db->sql_query( "SELECT id, listcatid FROM `" . $db_config['prefix'] . "_" . $lang_data . "_news_rows` ORDER BY `id` ASC" );
  150. while( list( $id, $listcatid ) = $db->sql_fetchrow( $result ) )
  151. {
  152. $arr_catid = explode( ",", $listcatid );
  153. foreach( $arr_catid as $catid )
  154. {
  155. $db->sql_query( "INSERT INTO `" . $db_config['prefix'] . "_" . $lang_data . "_news_" . $catid . "` SELECT * FROM `" . $db_config['prefix'] . "_" . $lang_data . "_news_rows` WHERE `id`=" . $id . "" );
  156. }
  157. }
  158. $db->sql_freeresult();
  159. }
  160. }
  161. }
  162. $nv_Request->set_Cookie( 'data_lang', $keylang, NV_LIVE_COOKIE_TIME );
  163. $xtpl->assign( 'URL', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=settings&" . NV_OP_VARIABLE . "=main" );
  164. $xtpl->parse( 'contents_setup' );
  165. $contents = $xtpl->text( 'contents_setup' );
  166. include ( NV_ROOTDIR . "/includes/header.php" );
  167. echo nv_admin_theme( $contents );
  168. include ( NV_ROOTDIR . "/includes/footer.php" );
  169. exit();
  170. }
  171. }
  172. elseif( $checksess == md5( $deletekeylang . session_id() . "deletekeylang" ) and ! in_array( $deletekeylang, $global_config['allow_sitelangs'] ) )
  173. {
  174. define( 'NV_IS_FILE_MODULES', true );
  175. $lang = $deletekeylang;
  176. $sql = "SELECT `title`, `module_file`, `module_data` FROM `" . $db_config['prefix'] . "_" . $lang . "_modules` ORDER BY `weight` ASC";
  177. $result_del_module = $db->sql_query( $sql );
  178. while( list( $title, $module_file, $module_data ) = $db->sql_fetchrow( $result_del_module ) )
  179. {
  180. if( file_exists( NV_ROOTDIR . '/modules/' . $module_file . '/action.php' ) )
  181. {
  182. $sql_drop_module = array();
  183. include ( NV_ROOTDIR . '/modules/' . $module_file . '/action.php' );
  184. if( ! empty( $sql_drop_module ) )
  185. {
  186. foreach( $sql_drop_module as $sql )
  187. {
  188. $db->sql_query( $sql );
  189. }
  190. }
  191. }
  192. }
  193. require_once ( NV_ROOTDIR . '/includes/sqldata.php' );
  194. $sql_drop_table = nv_delete_table_sys( $deletekeylang );
  195. foreach( $sql_drop_table as $query )
  196. {
  197. $db->sql_query( $query );
  198. }
  199. $db->sql_query( "DELETE FROM `" . NV_CONFIG_GLOBALTABLE . "` WHERE `lang` = '" . $deletekeylang . "'" );
  200. $db->sql_query( "DELETE FROM `" . $db_config['prefix'] . "_setup_language` WHERE `lang` = '" . $deletekeylang . "'" );
  201. nv_delete_all_cache();
  202. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['nv_setup_delete'], " langkey : " . $deletekeylang, $admin_info['userid'] );
  203. Header( 'Location: ' . NV_BASE_ADMINURL . 'index.php?' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $op . '&' . NV_LANG_VARIABLE . '=' . $global_config['site_lang'] . '&rand=' . nv_genpass() );
  204. exit();
  205. }
  206. $a = 0;
  207. foreach( $global_config['allow_adminlangs'] as $keylang )
  208. {
  209. $delete = "";
  210. $allow_sitelangs = "";
  211. $xtpl->assign( 'ROW', array(
  212. 'class' => ( ++ $a % 2 ) ? " class=\"second\"" : "",
  213. 'keylang' => $keylang,
  214. 'name' => $language_array[$keylang]['name'],
  215. ) );
  216. if( isset( $array_lang_setup[$keylang] ) and $array_lang_setup[$keylang] == 1 )
  217. {
  218. if( ! in_array( $keylang, $global_config['allow_sitelangs'] ) )
  219. {
  220. $xtpl->assign( 'DELETE', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $op . "&amp;deletekeylang=" . $keylang . "&amp;checksess=" . md5( $keylang . session_id() . "deletekeylang" ) );
  221. $xtpl->parse( 'main.loop.setup_delete' );
  222. }
  223. else
  224. {
  225. $xtpl->parse( 'main.loop.setup_note' );
  226. }
  227. if( $keylang != $global_config['site_lang'] )
  228. {
  229. $selected_yes = $selected_no = " ";
  230. if( in_array( $keylang, $global_config['allow_sitelangs'] ) )
  231. {
  232. $selected_yes = " selected=\"selected\"";
  233. }
  234. else
  235. {
  236. $selected_no = " selected=\"selected\"";
  237. }
  238. $xtpl->assign( 'ALLOW_SITELANGS', array(
  239. 'selected_yes' => $selected_yes,
  240. 'selected_no' => $selected_no,
  241. 'url_yes' => NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $op . "&amp;keylang=" . $keylang . "&amp;activelang=1&amp;checksess=" . md5( "activelang_" . $keylang . session_id() ),
  242. 'url_no' => NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $op . "&amp;keylang=" . $keylang . "&amp;activelang=0&amp;checksess=" . md5( "activelang_" . $keylang . session_id() )
  243. ) );
  244. $xtpl->parse( 'main.loop.allow_sitelangs' );
  245. }
  246. else
  247. {
  248. $xtpl->parse( 'main.loop.allow_sitelangs_note' );
  249. }
  250. }
  251. else
  252. {
  253. $xtpl->assign( 'INSTALL', NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=" . $op . "&amp;keylang=" . $keylang . "&amp;checksess=" . md5( $keylang . session_id() ) );
  254. $xtpl->parse( 'main.loop.setup_new' );
  255. }
  256. $xtpl->parse( 'main.loop' );
  257. }
  258. $contents .= " </table>\n";
  259. $contents .= "<div class=\"quote\" style=\"width:97.5%;\">\n";
  260. $contents .= "<blockquote><span>" . $lang_module['nv_data_note'] . "</span></blockquote>\n";
  261. $contents .= "</div>\n";
  262. $contents .= "<div class=\"clear\"></div>\n";
  263. $xtpl->parse( 'main' );
  264. $contents = $xtpl->text( 'main' );
  265. include ( NV_ROOTDIR . "/includes/header.php" );
  266. echo nv_admin_theme( $contents );
  267. include ( NV_ROOTDIR . "/includes/footer.php" );
  268. ?>