PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website nội thất PHP/noithatviet/modules/archives/admin/cat.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 217 lines | 188 code | 8 blank | 21 comment | 29 complexity | e6dc7028152b1a75d2b711e182ea76d3 MD5 | raw file
  1. <?php
  2. /**
  3. * @Project Archives OF NUKEVIET 3.x
  4. * @Author PCD-GROUP (contact@dinhpc.com)
  5. * @Copyright (C) 2011 PCD-GROUP. All rights reserved
  6. * @Createdate July 27, 2011 11:24:58 AM
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. $page_title = $lang_module['category'];
  10. $groups_list = nv_groups_list();
  11. $contents = "";
  12. $error = "";
  13. $parentid = $nv_Request->get_int( 'parentid', 'get', 0 );
  14. $catid = $nv_Request->get_int( 'catid', 'get,post', 0 );
  15. $data = array(
  16. "catid"=>0, "parentid"=>0, "title"=>"", "alias"=>"", "description"=>"", "image"=>"",
  17. "thumbnail"=>"", "weight"=>0, "order"=>0, "lev"=>0, "viewcat"=>"viewcat_list", "numsubcat"=>0,
  18. "subcatid"=>"", "inhome"=>1, "numlinks"=>3, "keywords"=>"", "admins"=>0, "add_time"=>NV_CURRENTTIME,
  19. "edit_time"=>NV_CURRENTTIME, "del_cache_time"=>0, "who_view"=>0, "groups_view"=>"","numrow"=>0
  20. );
  21. //post data
  22. if ( $nv_Request->get_int( 'save', 'post', 0 ) == '1' )
  23. {
  24. $data['catid'] = $nv_Request->get_int( 'catid', 'post', 0 );
  25. $parentid_old = $nv_Request->get_int( 'parentid_old', 'post', 0 );
  26. $data['parentid'] = $nv_Request->get_int( 'parentid', 'post', 0 );
  27. $data['title'] = filter_text_input( 'title', 'post', '', 1 );
  28. $data['keywords'] = filter_text_input( 'keywords', 'post', '', 1 );
  29. $alias = filter_text_input( 'alias', 'post', '' );
  30. $data['alias'] = ( $alias == "" ) ? change_alias( $data['title'] ) : change_alias( $alias );
  31. $description = $nv_Request->get_string( 'description', 'post', '' );
  32. $data['description'] = nv_nl2br( nv_htmlspecialchars( strip_tags( $description ) ), '<br />' );
  33. $data['who_view'] = $nv_Request->get_int( 'who_view', 'post', 0 );
  34. $groups = $nv_Request->get_typed_array( 'groups_view', 'post', 'int', array() );
  35. $groups = array_intersect( $groups, array_keys( $groups_list ) );
  36. $data['groups_view'] = implode( ",", $groups );
  37. if ( empty($data['title']) ) $error = $lang_module['cat_title_erorr'];
  38. else
  39. {
  40. if ($catid==0)
  41. {
  42. //insert data
  43. list( $weight ) = $db->sql_fetchrow( $db->sql_query( "SELECT max(`weight`) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` WHERE `parentid`=" . $db->dbescape( $data['parentid'] ) . "" ) );
  44. $weight = intval( $weight ) + 1;
  45. $query = "INSERT INTO `" . NV_PREFIXLANG . "_" . $module_data . "_cat` (`catid`, `parentid`, `title`, `alias`, `description`, `image`, `thumbnail`, `weight`, `order`, `lev`, `viewcat`, `numsubcat`, `subcatid`, `inhome`, `numlinks`, `keywords`, `admins`, `add_time`, `edit_time`, `del_cache_time`, `who_view`, `groups_view`,`numrow`)
  46. VALUES (NULL, " . $db->dbescape( $data['parentid'] ) . ", " . $db->dbescape( $data['title'] ) . ", " . $db->dbescape( $data['alias'] ) . ", " . $db->dbescape( $data['description'] ) . ", '', '', " . $db->dbescape( $weight ) . ", '0', '0', " . $db->dbescape( $data['viewcat'] ) . ", '0', " . $db->dbescape( $data['subcatid'] ) . ", '1', '3', " . $db->dbescape( $data['keywords'] ) . ", '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + 26000000, " . $db->dbescape( $data['who_view'] ) . "," . $db->dbescape( $data['groups_view'] ) . "," . $db->dbescape( $data['numrow'] ) . ")";
  47. $newcatid = intval( $db->sql_query_insert_id( $query ) );
  48. if ( $newcatid > 0 )
  49. {
  50. nv_fix_cat_order();
  51. nv_del_moduleCache( $module_name );
  52. nv_insert_logs( NV_LANG_DATA, $module_name,$lang_module['add_cat'], $data['title'], $admin_info['userid'] );
  53. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&parentid=" . $data['parentid'] . "" );
  54. die();
  55. }
  56. else
  57. {
  58. $error = $lang_module['errorsave'];
  59. }
  60. $db->sql_freeresult();
  61. }
  62. elseif($catid>0)
  63. {
  64. //update data
  65. $query = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_cat` SET `parentid`=" . $db->dbescape( $data['parentid'] ) . ", `title`=" . $db->dbescape( $data['title'] ) . ", `alias` = " . $db->dbescape( $data['alias'] ) . ", `description`=" . $db->dbescape( $data['description'] ) . ", `keywords`= " . $db->dbescape( $data['keywords'] ) . ", `who_view`=" . $db->dbescape( $data['who_view'] ) . ", `groups_view`=" . $db->dbescape( $data['groups_view'] ) . ", `edit_time`=UNIX_TIMESTAMP( ) WHERE `catid` =" . $catid . "";
  66. $db->sql_query( $query );
  67. if ( $db->sql_affectedrows() > 0 )
  68. {
  69. if ( $data['parentid'] != $parentid_old )
  70. {
  71. list( $weight ) = $db->sql_fetchrow( $db->sql_query( "SELECT max(`weight`) FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` WHERE `parentid`=" . $db->dbescape( $data['parentid'] ) . "" ) );
  72. $weight = intval( $weight ) + 1;
  73. $sql = "UPDATE `" . NV_PREFIXLANG . "_" . $module_data . "_cat` SET `weight`=" . $weight . " WHERE `catid`=" . intval( $catid );
  74. $db->sql_query( $sql );
  75. nv_fix_cat_order();
  76. nv_fix_cat_row ( $catid );
  77. }
  78. nv_insert_logs( NV_LANG_DATA, $module_name,$lang_module['edit_cat'], $data['title'], $admin_info['userid'] );
  79. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&parentid=" . $data['parentid'] . "" );
  80. die();
  81. }
  82. else
  83. {
  84. $error = $lang_module['errorsave'];
  85. }
  86. $db->sql_freeresult();
  87. }
  88. }
  89. }
  90. //select data
  91. if ( $catid > 0)
  92. {
  93. $sql = "SELECT * FROM `" . NV_PREFIXLANG . "_" . $module_data . "_cat` WHERE `catid` = '" . $catid . "' ORDER BY `weight` ASC";
  94. $result = $db->sql_query( $sql );
  95. $data = $db->sql_fetchrow( $result,2 );
  96. }
  97. /**
  98. * begin: listview data
  99. */
  100. $xtpl = new XTemplate( "cat.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  101. $xtpl->assign( 'LANG', $lang_module );
  102. if ( $parentid > 0 )
  103. {
  104. $parentid_i = $parentid;
  105. $array_cat_title = array();
  106. while ( $parentid_i > 0 )
  107. {
  108. $array_cat_title[] = "<a href=\"" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=cat&amp;parentid=" . $parentid_i . "\"><strong>" . $global_array_cat[$parentid_i]['title'] . "</strong></a>";
  109. $parentid_i = $global_array_cat[$parentid_i]['parentid'];
  110. }
  111. sort( $array_cat_title, SORT_NUMERIC );
  112. $ptemp = "<a href=\"" . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=cat&amp;parentid=0\"><strong>" . $lang_module['root_cat'] . "</strong></a>";
  113. $contents .= $ptemp." -> ".implode( " -> ", $array_cat_title );
  114. }
  115. $num = 1;
  116. foreach ( $global_array_cat as $row )
  117. {
  118. if ( $row['parentid'] == $parentid ) $num++;
  119. }
  120. if ( $num > 0 )
  121. {
  122. $array_inhome = array(
  123. 0 => $lang_global['no'], 1 => $lang_global['yes']
  124. );
  125. $array_viewcat = array(
  126. "viewcat_list" => $lang_module['list'], "viewcat_gird" => $lang_module['gird']
  127. );
  128. $a = 1;
  129. foreach ( $global_array_cat as $row )
  130. {
  131. if ( $row['parentid'] == $parentid )
  132. {
  133. $row['class'] = ( $a % 2 ) ? " class=\"second\"" : "";
  134. $row['sinhome'] = drawselect_status( "inhome", $array_inhome, $row['inhome'],"ChangeActiveCat(this,".$row['catid'].",'active')" );
  135. $row['sweight'] = drawselect_number( "weight", 1, $num-1, $row['weight'],"ChangeActiveCat(this,".$row['catid'].",'weight')" );
  136. $row['snumlinks'] = drawselect_number( "numlinks", 1, 50, $row['numlinks'],"ChangeActiveCat(this,".$row['catid'].",'numlinks')" );
  137. $row['sviewcat'] = drawselect_status( "viewcat", $array_viewcat, $row['viewcat'],"ChangeActiveCat(this,".$row['catid'].",'viewcat')" );
  138. $row['edit'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=cat&amp;parentid=" . $row['parentid']."&amp;catid=" . $row['catid'];
  139. $row['del'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=cat_action&amp;ac=del&amp;catid=" . $row['catid'];
  140. $row['add'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=content&amp;catid=" . $row['catid'];
  141. $row['linkparent'] = NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&amp;" . NV_OP_VARIABLE . "=cat&amp;parentid=" . $row['catid'];
  142. $xtpl->assign( 'ROW', $row );
  143. $xtpl->parse( 'main.list.loop' );
  144. }
  145. }
  146. $xtpl->parse( 'main.list' );
  147. }
  148. /**
  149. * end: listview data
  150. */
  151. /**
  152. * view form data
  153. */
  154. if ( ! empty( $error ) )
  155. {
  156. $xtpl->assign( 'ERROR', $error );
  157. $xtpl->parse( 'main.form.error' );
  158. }
  159. foreach ( $global_array_cat as $catid_i => $array_value )
  160. {
  161. if ( $catid_i != $catid )
  162. {
  163. $xtitle_i = "";
  164. if ( $array_value['lev'] > 0 )
  165. {
  166. $xtitle_i .= "&nbsp;&nbsp;&nbsp;|";
  167. for ( $i = 1; $i <= $array_value['lev']; $i ++ )
  168. {
  169. $xtitle_i .= "---";
  170. }
  171. $xtitle_i .= "&nbsp;";
  172. }
  173. $select = ( $catid_i == $parentid ) ? 'selected="selected"' : '';
  174. $array_cat = array( "xtitle"=> $xtitle_i.$array_value['title'], "catid"=>$catid_i,"select"=>$select);
  175. $xtpl->assign( 'ROW', $array_cat );
  176. $xtpl->parse( 'main.form.catlist' );
  177. }
  178. }
  179. if ( empty( $data['alias'] ) )
  180. {
  181. $xtpl->parse( 'main.form.getalias' );
  182. }
  183. //$array_who_view
  184. $xtpl->assign( 'who_views', drawselect_status( "who_view", $array_who_view, $data['who_view'],'show_group()' ) );
  185. //$groups_list
  186. if (!empty($groups_list))
  187. {
  188. $groups_view = explode( ",", $data['groups_view'] );
  189. foreach ( $groups_list as $groups_id=> $groups_title )
  190. {
  191. $check = "";
  192. if ( in_array($groups_id, $groups_view) )
  193. {
  194. $check = 'checked="checked"';
  195. }
  196. $data_temp = array( "value"=> $groups_id, "title"=> $groups_title ,"check"=>$check);
  197. $xtpl->assign( 'groups_views', $data_temp );
  198. $xtpl->parse( 'main.form.groups_views' );
  199. }
  200. }
  201. $xtpl->assign( 'hidediv', $data['who_view'] == 3 ? "visibility:visible" : "visibility:hidden" );
  202. $xtpl->assign( 'DATA', $data );
  203. $xtpl->parse( 'main.form' );
  204. $xtpl->parse( 'main' );
  205. $contents .= $xtpl->text( 'main' );
  206. include ( NV_ROOTDIR . "/includes/header.php" );
  207. echo nv_admin_theme( $contents );
  208. include ( NV_ROOTDIR . "/includes/footer.php" );
  209. ?>