PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website trường trung học phổ thông PHP/lc1/modules/shops/admin/cat.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 213 lines | 187 code | 17 blank | 9 comment | 28 complexity | cd6bc36adbe2ba9a3a7c254ad0fd7abe MD5 | raw file
  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-9-2010 14:43
  7. */
  8. if ( ! defined( 'NV_IS_FILE_ADMIN' ) ) die( 'Stop!!!' );
  9. $page_title = $lang_module['cat_title'];
  10. $table_name = $db_config['prefix'] . "_" . $module_data . "_catalogs";
  11. $error = $admins = "";
  12. $savecat = 0;
  13. $data = array();
  14. list( $data['catid'], $data['parentid'], $data['title'], $data['alias'], $data['description'], $data['keywords'], $data['who_view'], $groups_view ) = array(
  15. 0, 0, "", "", "", "", 0, ""
  16. );
  17. $groups_list = nv_groups_list();
  18. $savecat = $nv_Request->get_int( 'savecat', 'post', 0 );
  19. if ( ! empty( $savecat ) )
  20. {
  21. $field_lang = nv_file_table( $table_name );
  22. $data['catid'] = $nv_Request->get_int( 'catid', 'post', 0 );
  23. $data['parentid_old'] = $nv_Request->get_int( 'parentid_old', 'post', 0 );
  24. $data['parentid'] = $nv_Request->get_int( 'parentid', 'post', 0 );
  25. $data['title'] = filter_text_input( 'title', 'post', '', 1 );
  26. $data['keywords'] = filter_text_input( 'keywords', 'post', '', 1 );
  27. $data['alias'] = filter_text_input( 'alias', 'post', '' );
  28. $data['description'] = $nv_Request->get_string( 'description', 'post', '' );
  29. $data['description'] = nv_substr( $data['description'], 0, 255 );
  30. $data['description'] = nv_nl2br( nv_htmlspecialchars( strip_tags( $data['description'] ) ), '<br />' );
  31. $data['alias'] = ( $data['alias'] == "" ) ? change_alias( $data['title'] ) : change_alias( $data['alias'] );
  32. $data['who_view'] = $nv_Request->get_int( 'who_view', 'post', 0 );
  33. $groups_view = "";
  34. $data['groups'] = $nv_Request->get_typed_array( 'groups_view', 'post', 'int', array() );
  35. $groups = array_intersect( $data['groups'], array_keys( $groups_list ) );
  36. $groups_view = implode( ",", $data['groups'] );
  37. if ( $data['title'] == "" )
  38. {
  39. $error = $lang_module['error_cat_name'];
  40. }
  41. list( $check_alias ) = $db->sql_fetchrow( $db->sql_query( "SELECT count(*) FROM " . $table_name . " WHERE catid!=" . $data['catid'] . " and `" . NV_LANG_DATA . "_alias`=" . $db->dbescape( $data['alias'] ) . "" ) );
  42. if ( $check_alias and $data['parentid'] > 0 )
  43. {
  44. list( $parentid_alias ) = $db->sql_fetchrow( $db->sql_query( "SELECT `" . NV_LANG_DATA . "_alias` FROM " . $table_name . " WHERE catid=" . $data['parentid'] . "" ) );
  45. $data['alias'] = $parentid_alias . "-" . $data['alias'];
  46. }
  47. if ( $data['catid'] == 0 and $data['title'] != "" and $error == "" )
  48. {
  49. $listfield = "";
  50. $listvalue = "";
  51. foreach ( $field_lang as $field_lang_i )
  52. {
  53. list( $flang, $fname ) = $field_lang_i;
  54. $listfield .= ", `" . $flang . "_" . $fname . "`";
  55. if ( $flang == NV_LANG_DATA )
  56. {
  57. $listvalue .= ", " . $db->dbescape( $data[$fname] );
  58. }
  59. else
  60. {
  61. $listvalue .= ", " . $db->dbescape( $data[$fname] );
  62. }
  63. }
  64. list( $weight ) = $db->sql_fetchrow( $db->sql_query( "SELECT max(`weight`) FROM " . $table_name . " WHERE `parentid`=" . $db->dbescape( $data['parentid'] ) . "" ) );
  65. $weight = intval( $weight ) + 1;
  66. $viewcat = "viewcat_page_list";
  67. $subcatid = "";
  68. $query = "INSERT INTO " . $table_name . " (`catid`, `parentid`, `image`, `thumbnail`, `weight`, `order`, `lev`, `viewcat`, `numsubcat`, `subcatid`, `inhome`, `numlinks`, `admins`, `add_time`, `edit_time`, `del_cache_time`, `who_view`, `groups_view` " . $listfield . " )
  69. VALUES (NULL, " . $db->dbescape( $data['parentid'] ) . ",' ',' '," . $db->dbescape( $weight ) . ", '0', '0', " . $db->dbescape( $viewcat ) . ", '0', " . $db->dbescape( $subcatid ) . ", '1', '4'," . $db->dbescape( $admins ) . ", UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + 26000000, " . $db->dbescape( $data['who_view'] ) . "," . $db->dbescape( $groups_view ) . $listvalue . " )";
  70. $newcatid = intval( $db->sql_query_insert_id( $query ) );
  71. if ( $newcatid > 0 )
  72. {
  73. nv_insert_logs( NV_LANG_DATA, $module_name, 'log_add_catalog', "id " . $newcatid, $admin_info['userid'] );
  74. $db->sql_freeresult();
  75. nv_fix_cat_order();
  76. nv_del_moduleCache( $module_name );
  77. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&parentid=" . $data['parentid'] . "" );
  78. die();
  79. }
  80. else
  81. {
  82. //$error = $query;
  83. $error = $lang_module['errorsave'];
  84. }
  85. }
  86. elseif ( $data['catid'] > 0 and $data['title'] != "" and $error == "" )
  87. {
  88. $query = "UPDATE " . $table_name . " SET `parentid`=" . $db->dbescape( $data['parentid'] ) . ", `" . NV_LANG_DATA . "_title`=" . $db->dbescape( $data['title'] ) . ", `" . NV_LANG_DATA . "_alias` = " . $db->dbescape( $data['alias'] ) . ", `" . NV_LANG_DATA . "_description`=" . $db->dbescape( $data['description'] ) . ", `" . NV_LANG_DATA . "_keywords`= " . $db->dbescape( $data['keywords'] ) . ", `who_view`=" . $db->dbescape( $data['who_view'] ) . ", `groups_view`=" . $db->dbescape( $groups_view ) . ", `edit_time`=UNIX_TIMESTAMP( ) WHERE `catid` =" . $data['catid'] . "";
  89. $db->sql_query( $query );
  90. if ( $db->sql_affectedrows() > 0 )
  91. {
  92. nv_insert_logs( NV_LANG_DATA, $module_name, 'log_edit_catalog', "id " . $data['catid'], $admin_info['userid'] );
  93. $db->sql_freeresult();
  94. if ( $data['parentid'] != $data['parentid_old'] )
  95. {
  96. list( $weight ) = $db->sql_fetchrow( $db->sql_query( "SELECT max(`weight`) FROM " . $table_name . " WHERE `parentid`=" . $db->dbescape( $data['parentid'] ) . "" ) );
  97. $weight = intval( $weight ) + 1;
  98. $sql = "UPDATE " . $table_name . " SET `weight`=" . $weight . " WHERE `catid`=" . intval( $data['catid'] );
  99. $db->sql_query( $sql );
  100. nv_fix_cat_order();
  101. }
  102. nv_del_moduleCache( $module_name );
  103. Header( "Location: " . NV_BASE_ADMINURL . "index.php?" . NV_NAME_VARIABLE . "=" . $module_name . "&" . NV_OP_VARIABLE . "=" . $op . "&parentid=" . $data['parentid'] . "" );
  104. die();
  105. }
  106. else
  107. {
  108. $error = $lang_module['errorsave'];
  109. }
  110. $db->sql_freeresult();
  111. }
  112. else
  113. {
  114. //$error = $lang_module['error_name'];
  115. }
  116. }
  117. $data['parentid'] = $nv_Request->get_int( 'parentid', 'get,post', 0 );
  118. $contents = "<div id=\"module_show_list\">";
  119. $contents .= nv_show_cat_list( $data['parentid'] );
  120. $contents .= "</div>\n";
  121. $data['catid'] = $nv_Request->get_int( 'catid', 'get', 0 );
  122. if ( $data['catid'] > 0 )
  123. {
  124. list( $data['catid'], $data['parentid'], $data['title'], $data['alias'], $data['description'], $data['keywords'], $data['who_view'], $data['groups_view'] ) = $db->sql_fetchrow( $db->sql_query( "SELECT `catid`, `parentid`, `" . NV_LANG_DATA . "_title`, `" . NV_LANG_DATA . "_alias`, `" . NV_LANG_DATA . "_description`, `" . NV_LANG_DATA . "_keywords`, `who_view`, `groups_view` FROM " . $table_name . " where `catid`=" . $data['catid'] . "" ) );
  125. $caption = $lang_module['edit_cat'];
  126. }
  127. else
  128. {
  129. $caption = $lang_module['add_cat'];
  130. }
  131. $groups_view = explode( ",", $groups_view );
  132. $sql = "SELECT catid, " . NV_LANG_DATA . "_title, lev FROM " . $table_name . " WHERE `catid` !='" . $data['catid'] . "' ORDER BY `order` ASC";
  133. $result = $db->sql_query( $sql );
  134. $array_cat_list = array();
  135. $array_cat_list[0] = array(
  136. '0', $lang_module['cat_sub_sl']
  137. );
  138. while ( list( $catid_i, $title_i, $lev_i ) = $db->sql_fetchrow( $result ) )
  139. {
  140. $xtitle_i = "";
  141. if ( $lev_i > 0 )
  142. {
  143. $xtitle_i .= "&nbsp;";
  144. for ( $i = 1; $i <= $lev_i; $i ++ )
  145. {
  146. $xtitle_i .= "---";
  147. }
  148. }
  149. $xtitle_i .= $title_i;
  150. $array_cat_list[] = array(
  151. $catid_i, $xtitle_i
  152. );
  153. }
  154. // * call theme tpl of product catalogs */
  155. $xtpl = new XTemplate( "cat_add.tpl", NV_ROOTDIR . "/themes/" . $global_config['module_theme'] . "/modules/" . $module_file );
  156. $xtpl->assign( 'LANG', $lang_module );
  157. $xtpl->assign( 'caption', $caption );
  158. $xtpl->assign( 'who_view', $lang_global['who_view'] );
  159. $xtpl->assign( 'groups_view', $lang_global['groups_view'] );
  160. $xtpl->assign( 'DATA', $data );
  161. if ( $error != "" )
  162. {
  163. $xtpl->assign( 'error', $error );
  164. $xtpl->parse( 'main.error' );
  165. }
  166. foreach ( $array_cat_list as $rows_i )
  167. {
  168. $sl = ( $rows_i[0] == $data['parentid'] ) ? " selected=\"selected\"" : "";
  169. $xtpl->assign( 'pcatid_i', $rows_i[0] );
  170. $xtpl->assign( 'ptitle_i', $rows_i[1] );
  171. $xtpl->assign( 'pselect', $sl );
  172. $xtpl->parse( 'main.parent_loop' );
  173. }
  174. $contents_html = "";
  175. foreach ( $array_who_view as $k => $w )
  176. {
  177. $sl = ( $data['who_view'] == $k ) ? " selected=\"selected\"" : "";
  178. $contents_html .= " <option value=\"" . $k . "\" " . $sl . ">" . $w . "</option>\n";
  179. }
  180. $xtpl->assign( 'who_view_html', $contents_html );
  181. $visibility = ( $data['who_view'] == 3 ) ? "visibility:visible;display:block;" : "visibility:hidden;display:none;";
  182. $xtpl->assign( 'visibility', $visibility );
  183. $contents_html = "";
  184. foreach ( $groups_list as $group_id => $grtl )
  185. {
  186. $contents_html .= "<p><input name=\"groups_view[]\" type=\"checkbox\" value=\"" . $group_id . "\"";
  187. if ( in_array( $group_id, $groups_view ) ) $contents_html .= " checked=\"checked\"";
  188. $contents_html .= " />&nbsp;" . $grtl . "</p>\n";
  189. }
  190. $xtpl->assign( 'groups_list_html', $contents_html );
  191. $xtpl->parse( 'main' );
  192. $contents .= $xtpl->text( 'main' );
  193. include ( NV_ROOTDIR . "/includes/header.php" );
  194. echo nv_admin_theme( $contents );
  195. include ( NV_ROOTDIR . "/includes/footer.php" );
  196. ?>