PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/xoops_trust_path/modules/coupons/admin/categories.php

http://xoopscube-modules.googlecode.com/
PHP | 119 lines | 90 code | 14 blank | 15 comment | 17 complexity | 94e3399e556854b45d1ef180c3fbb106 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. require_once XOOPS_ROOT_PATH.'/class/xoopslists.php';
  3. //category icon
  4. if(!empty($GLOBALS['xoopsModuleConfig']['categoryicon_path'])) {
  5. $imagepath = coupons_urlCheckReplace( $GLOBALS['xoopsModuleConfig']['categoryicon_path'] ) ;
  6. $imagepath = preg_replace( array("|^(.+)/$|") , array("$1") , $imagepath ) ;// remove trailing slash ???
  7. // for imgurl box
  8. $images_array = XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH."/".$imagepath );
  9. foreach($images_array as $img){
  10. $images[] = htmlspecialchars(coupons_urlCheckReplace($img), ENT_QUOTES);
  11. }
  12. }
  13. //INSERT , UPDATE
  14. if( isset($_POST['edit']) && !empty($_POST['title']) ){
  15. if ( ! $xoopsGTicket->check( true , 'coupons_admin_categories' ) ) {
  16. redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
  17. }
  18. if( isset($_POST['cid']) && $_POST['cid']>0 ){
  19. if( $_POST['cid'] == $_POST['pid'] ){
  20. $msg = "<span style='color:red;'>"._MD_CID_EQUAL_PID."</span>" ;
  21. }else{
  22. if( $categories->update(intval($_POST['cid'])) ){
  23. $msg = _MD_A_COUPONS_CAT_INSERTED ;
  24. }else{
  25. $msg = "<div class='warning'>"._MD_A_COUPONS_CAT_INSERT_ERR."</div>" ;
  26. }
  27. }
  28. }else{
  29. if( $categories->insert() ){
  30. $msg = _MD_A_COUPONS_CAT_INSERTED ;
  31. }else{
  32. $msg = "<div class='warning'>"._MD_A_COUPONS_CAT_INSERT_ERR."</div>" ;
  33. }
  34. }
  35. redirect_header( "$mydirurl/admin/index.php?page=categories" , 2 , $msg ) ;
  36. }
  37. //DELETE
  38. if( @$_POST['delcat']==1 && @$_POST['cid']>0 ){
  39. if ( ! $xoopsGTicket->check( true , 'coupons_admin_categories' ) ) {
  40. redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
  41. }
  42. $delcid = intval($_POST['cid']) ;
  43. if( $categories->delete( $delcid ) ){
  44. $msg = _MD_A_COUPONS_CAT_DELETED ;
  45. $childIds =& $categories->getAllChildId($delcid);
  46. $childIds[] = $delcid ;
  47. //delete coupons
  48. if( $dellidnum = $coupons->deleteByCid($childIds) ){
  49. $msg .= "<br />( ". _MD_COUPON_DELETED ." : $dellidnum )" ;
  50. }
  51. }else{
  52. $msg = "<div class='warning'>". _MD_A_COUPONS_CAT_DELETED_ERR ."</div>" ;
  53. }
  54. redirect_header( "$mydirurl/admin/index.php?page=categories" , 2 , $msg ) ;
  55. }
  56. //edit category
  57. $editcat = false ;
  58. if( isset($_GET['cid']) ){
  59. $editcat = $categories->getCategory( intval($_GET['cid']) );
  60. }
  61. //category tree
  62. $cat_tree_array = $categories->getChildTreeArray( 0 , 'corder,cid' ) ;
  63. //pid selector
  64. /*ob_start();
  65. $selected_id = isset($editcat['pid']) ? $editcat['pid'] : 0 ;
  66. $categories->makeMySelBox('corder,cid',$selected_id,true,'pid',"","pid",0);
  67. $pidSelector = ob_get_contents() ;
  68. ob_end_clean();*/
  69. $selected_id = isset($editcat['pid']) ? $editcat['pid'] : 0 ;
  70. $pidSelector = $categories->makeMySelBox('corder,cid',$selected_id,true,'pid',"","pid",0);
  71. /* ------------------------------------------------------------------ */
  72. xoops_cp_header() ;
  73. include dirname(__FILE__).'/mymenu.php' ;
  74. $tpl =& new XoopsTpl() ;
  75. foreach( $cat_tree_array as $cat_node ) {
  76. extract( $cat_node ) ;
  77. $prefix = str_replace( '.' , '&nbsp;--' , substr( $prefix , 1 ) ) ;
  78. $imgurl = coupons_urlCheckReplace( $imgurl ) ;
  79. $itemnum = getItemsNum($cid);
  80. $tpl->append( 'categories' , array(
  81. 'cid' => $cid ,
  82. 'pid' => $pid ,
  83. 'corder' => $corder ,
  84. 'prefix' => $prefix ,
  85. 'title' => htmlspecialchars($title, ENT_QUOTES) ,
  86. 'imgurl' => $imgurl ,
  87. 'itemnum' => $itemnum ,
  88. ) );
  89. }
  90. if( $editcat ) {
  91. $tpl->assign( 'editcat' , $editcat ) ;
  92. }
  93. $tpl->assign( array(
  94. 'mod_name' => $xoopsModule->getVar('name') ,
  95. 'menu_name' => constant($constprefMI.'_ADMENU1') ,
  96. 'myurl' => $mydirurl ,
  97. 'pidselector' => $pidSelector ,
  98. 'imgfiles' => $images ,
  99. 'imgpath' => htmlspecialchars($imagepath,ENT_QUOTES) ,
  100. 'gticket' => $xoopsGTicket->getTicketHtml( __LINE__ , 1800 , 'coupons_admin_categories' ) ,
  101. ) ) ;
  102. $tpl->display( 'db:'.$mydirname.'_admin_categories.html' ) ;
  103. xoops_cp_footer();
  104. /* ------------------------------------------------------------------ */
  105. ?>