PageRenderTime 23ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/01.Source/01.CORE/modules/news/admin/del_cat.php

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