PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/NukeViet3.2/modules/news/admin/del_cat.php

http://nuke-viet.googlecode.com/
PHP | 192 lines | 175 code | 11 blank | 6 comment | 26 complexity | 72ae78c1dfe283c71f90bbe3c10919e4 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0
  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 2-10-2010 18:49
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. $catid = $nv_Request->get_int( 'catid', 'post', 0 );
  10. $contents = "NO_" . $catid;
  11. list( $catid, $parentid, $title ) = $db->sql_fetchrow( $db->sql_query( "SELECT `catid`, `parentid`, `title` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` WHERE `catid`=" . intval( $catid ) . "" ) );
  12. if ( $catid > 0 )
  13. {
  14. if ( ( defined( 'NV_IS_ADMIN_MODULE' ) or ( $parentid > 0 and isset( $array_cat_admin[$admin_id][$parentid] ) and $array_cat_admin[$admin_id][$parentid]['admin'] == 1 ) ) )
  15. {
  16. $delallcheckss = $nv_Request->get_string( 'delallcheckss', 'post', "" );
  17. list( $check_parentid ) = $db->sql_fetchrow( $db->sql_query( "SELECT count(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` WHERE `parentid` = '" . $catid . "'" ) );
  18. if ( intval( $check_parentid ) > 0 )
  19. {
  20. $contents = "ERR_CAT_" . sprintf( $lang_module['delcat_msg_cat'], $check_parentid );
  21. }
  22. else
  23. {
  24. list( $check_rows ) = $db->sql_fetchrow( $db->sql_query( "SELECT count(*) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid . "`" ) );
  25. if ( intval( $check_rows ) > 0 )
  26. {
  27. if ( $delallcheckss == md5( $catid . session_id() . $global_config['sitekey'] ) )
  28. {
  29. $delcatandrows = $nv_Request->get_string( 'delcatandrows', 'post', "" );
  30. $movecat = $nv_Request->get_string( 'movecat', 'post', "" );
  31. $catidnews = $nv_Request->get_int( 'catidnews', 'post', 0 );
  32. if ( empty( $delcatandrows ) and empty( $movecat ) )
  33. {
  34. $sql = "SELECT catid, title, lev FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` WHERE `catid` !='" . $catid . "' ORDER BY `order` ASC";
  35. $result = $db->sql_query( $sql );
  36. $array_cat_list = array();
  37. $array_cat_list[0] = "&nbsp;";
  38. while ( list( $catid_i, $title_i, $lev_i ) = $db->sql_fetchrow( $result ) )
  39. {
  40. $xtitle_i = "";
  41. if ( $lev_i > 0 )
  42. {
  43. $xtitle_i .= "&nbsp;&nbsp;&nbsp;|";
  44. for ( $i = 1; $i <= $lev_i; $i ++ )
  45. {
  46. $xtitle_i .= "---";
  47. }
  48. $xtitle_i .= ">&nbsp;";
  49. }
  50. $xtitle_i .= $title_i;
  51. $array_cat_list[$catid_i] = $xtitle_i;
  52. }
  53. $contents = "<form action=\"" . NV_BASE_ADMINURL . "index.php\" method=\"post\">";
  54. $contents .= "<input type=\"hidden\" name =\"" . NV_NAME_VARIABLE . "\"value=\"" . $module_name . "\" />";
  55. $contents .= "<input type=\"hidden\" name =\"" . NV_OP_VARIABLE . "\"value=\"" . $op . "\" />";
  56. $contents .= "<input type=\"hidden\" name =\"catid\" value=\"" . $catid . "\" />";
  57. $contents .= "<input type=\"hidden\" name =\"delallcheckss\" value=\"" . $delallcheckss . "\" />";
  58. $contents .= "<center>";
  59. $contents .= "<b>" . sprintf( $lang_module['delcat_msg_rows_select'], $title, $check_rows ) . "</b>";
  60. $contents .= "<br /><br /><input name=\"delcatandrows\" type=\"submit\" value=\"" . $lang_module['delcatandrows'] . "\" />";
  61. $contents .= "<br /><br /><b>" . $lang_module['delcat_msg_rows_move'] . "</b>: <select name=\"catidnews\">\n";
  62. while ( list( $catid_i, $title_i ) = each( $array_cat_list ) )
  63. {
  64. $contents .= "<option value=\"" . $catid_i . "\">" . $title_i . "</option>\n";
  65. }
  66. $contents .= "</select><input name=\"movecat\" type=\"submit\" value=\"" . $lang_module['action'] . "\" onclick=\"return nv_check_movecat(this.form, '" . $lang_module['delcat_msg_rows_noselect'] . "')\">\n";
  67. $contents .= "</center>";
  68. $contents .= "</form>";
  69. }
  70. elseif ( ! empty( $delcatandrows ) )
  71. {
  72. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['delcatandrows'], $title, $admin_info['userid'] );
  73. $query = $db->sql_query( "SELECT id, listcatid FROM `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid . "`" );
  74. while ( $row = $db->sql_fetchrow( $query ) )
  75. {
  76. if ( ( string )$row['listcatid'] == ( string )$catid )
  77. {
  78. nv_del_content_module( $row['id'] );
  79. }
  80. else
  81. {
  82. $arr_catid_old = explode( ",", $row['listcatid'] );
  83. $arr_catid_i = array(
  84. $catid
  85. );
  86. $arr_catid_news = array_diff( $arr_catid_old, $arr_catid_i );
  87. foreach ( $arr_catid_news as $catid_i )
  88. {
  89. $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid_i . "` SET `listcatid` = '" . implode( ",", $arr_catid_news ) . "' WHERE `id` =" . $row['id'] );
  90. }
  91. $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_rows` SET `listcatid` = '" . implode( ",", $arr_catid_news ) . "' WHERE `id` =" . $row['id'] );
  92. }
  93. }
  94. $db->sql_query( "DROP TABLE `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid . "`" );
  95. $db->sql_query( "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` WHERE `catid`=" . $catid );
  96. $db->sql_query( "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_admins` WHERE `catid`=" . $catid );
  97. nv_fix_cat_order();
  98. nv_del_moduleCache( $module_name );
  99. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=cat&parentid=" . $parentid . "" );
  100. die();
  101. }
  102. elseif ( ! empty( $movecat ) and $catidnews > 0 and $catidnews != $catid )
  103. {
  104. list( $catidnews, $newstitle ) = $db->sql_fetchrow( $db->sql_query( "SELECT `catid`, `title` FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` WHERE `catid` =" . $catidnews ) );
  105. if ( $catidnews > 0 )
  106. {
  107. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['move'], $title . ' --> ' . $newstitle, $admin_info['userid'] );
  108. $query = $db->sql_query( "SELECT id, listcatid FROM `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid . "`" );
  109. while ( $row = $db->sql_fetchrow( $query ) )
  110. {
  111. $arr_catid_old = explode( ",", $row['listcatid'] );
  112. $arr_catid_i = array(
  113. $catid
  114. );
  115. $arr_catid_news = array_diff( $arr_catid_old, $arr_catid_i );
  116. if ( ! in_array( $catidnews, $arr_catid_news ) )
  117. {
  118. $db->sql_query( "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catidnews . "` SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_rows` WHERE `id`=" . $row['id'] . "" );
  119. $arr_catid_news[] = $catidnews;
  120. }
  121. foreach ( $arr_catid_news as $catid_i )
  122. {
  123. $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid_i . "` SET `listcatid` = '" . implode( ",", $arr_catid_news ) . "' WHERE `id` =" . $row['id'] );
  124. }
  125. $db->sql_query( "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_rows` SET `listcatid` = '" . implode( ",", $arr_catid_news ) . "' WHERE `id` =" . $row['id'] );
  126. }
  127. $db->sql_query( "DROP TABLE `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid . "`" );
  128. $db->sql_query( "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` WHERE `catid`=" . $catid );
  129. $db->sql_query( "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_admins` WHERE `catid`=" . $catid );
  130. nv_fix_cat_order();
  131. nv_del_moduleCache( $module_name );
  132. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=cat&parentid=" . $parentid . "" );
  133. die();
  134. }
  135. }
  136. }
  137. else
  138. {
  139. $contents = "ERR_ROWS_" . $catid . "_" . md5( $catid . session_id() . $global_config['sitekey'] ) . "_" . sprintf( $lang_module['delcat_msg_rows'], $check_rows );
  140. }
  141. }
  142. }
  143. if ( $contents == "NO_" . $catid )
  144. {
  145. if ( $delallcheckss == md5( $catid . session_id() ) )
  146. {
  147. $query = "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` WHERE catid=" . $catid . "";
  148. if ( $db->sql_query( $query ) )
  149. {
  150. nv_insert_logs( NV_LANG_DATA, $module_name, $lang_module['delcatandrows'], $title, $admin_info['userid'] );
  151. $db->sql_freeresult();
  152. nv_fix_cat_order();
  153. $db->sql_query( "DROP TABLE `" . NV_PREFIXLANG . "_" . $module_data . "_" . $catid . "`" );
  154. $contents = "OK_" . $parentid;
  155. }
  156. $db->sql_query( "DELETE FROM `" . NV_PREFIXLANG . "_" . $module_data . "_admins` WHERE `catid`=" . $catid );
  157. nv_del_moduleCache( $module_name );
  158. }
  159. else
  160. {
  161. $contents = "CONFIRM_" . $catid . "_" . md5( $catid . session_id() );
  162. }
  163. }
  164. }
  165. else
  166. {
  167. $contents = "ERR_CAT_" . $lang_module['delcat_msg_cat_permissions'];
  168. }
  169. }
  170. if ( defined( 'NV_IS_AJAX' ) )
  171. {
  172. include ( NV_ROOTDIR . "/includes/header.php" );
  173. echo $contents;
  174. include ( NV_ROOTDIR . "/includes/footer.php" );
  175. }
  176. else
  177. {
  178. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=cat" );
  179. die();
  180. }
  181. ?>