/home/banprang/domains/plai.go.th/public_html/coremain/manage_blog.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php

//#5.3#//if($p_id_!="")                            {         $id_=trim($p_id_);                        }
$id_ = isset($p_id_) ? $p_id_ '';
//#5.3#//if($p_id_del_top!="")                    {         $id_del_top=trim($p_id_del_top);        }
$id_del_top = isset($p_id_del_top) ? $p_id_del_top '';
//#5.3#//if($p_id_show!="")                        {         $id_show=trim($p_id_show);                }
$id_show = isset($p_id_show) ? $p_id_show '';
//#5.3#//if($p_tables!="")                        {         $tables=trim($p_tables);                }
$tables = isset($p_tables) ? $p_tables '';
//#5.3#//if($p_fields!="")                        {         $fields=trim($p_fields);                }
$fields = isset($p_fields) ? $p_fields '';
//#5.3#//if($p_left_right!="")                    {         $left_right=trim($p_left_right);        }
$left_right = isset($p_left_right) ? $p_left_right '';
//#5.3#//if($p_move_right!="")                    {         $move_right=trim($p_move_right);        }
$move_right = isset($p_move_right) ? $p_move_right '';
//#5.3#//if($p_id_order!="")                        {         $id_order=trim($p_id_order);            }
$id_order = isset($p_id_order) ? $p_id_order '';
//#5.3#//if($p_module!="")                        {         $module=trim($p_module);                }
$module = isset($p_module) ? $p_module '';

// #################### #######################
if ($id_ != "" and $id_show == 1) {
  
$sql "UPDATE `$tables` SET `status` = '0'  WHERE `$fields` ='$id_'";
  
$result mysql_query($sql);
}if (
$id_ != "" and $id_show == 2) {
  
$sql "UPDATE `$tables` SET `status` = '1'  WHERE `$fields` ='$id_'";
  
$result mysql_query($sql);
}

// ##########################################
if ($id_ != "" and $id_order != "") {
  
$sql "SELECT * FROM `$tables` WHERE left_right='$left_right' and id_top='$id_'";
  
$re mysql_query($sql);
  
$data mysql_fetch_array($re);
  if (
$id_order == 1) {
    
$up $data['position'] - 1;
  }
  if (
$id_order == 2) {
    
$up $data['position'] + 1;
  }
  
// 
  
$sql "UPDATE `$tables` SET position='$up' WHERE left_right='$left_right' and id_top ='$data[id_top]'";
  
$re mysql_query($sql);
  
// 
  
$sql "UPDATE `$tables` SET position='$data[position]'  WHERE left_right='$left_right' and id_top !='$data[id_top]' and position='$up'";
  
$re mysql_query($sql);

  
#echo "<meta http-equiv='refresh' content='0; url=index.php'>";
  
header"location: index.php?f=$id_);
  exit(
0);
}

// ###################  #####################
if ($id_ != "" and $move_right != "") {
//  if($move_right == '3'){
//    set_position($tables, $id_);
//    
//    $sql_num = "SELECT MAX(position) position FROM $tables WHERE left_right = '$move_right'";
//    $re_num = mysql_query($sql_num);
//    $data_num = mysql_fetch_array($re_num);
//    $posit = $data_num[0] + 1;
//    
//    
//  }else{
    
if ($move_right == "2")
      
$move_ 1;
    else if (
$move_right == "1")
      
$move_ 2;

    if(isset(
$p_top) && $p_top == '1'){
      
$posit 1;

      
$update1 "UPDATE `$tables` SET `left_right` = '$move_' WHERE `left_right` = '$move_right' AND `position` = '$posit'";
      
mysql_query($update1);
      
$update2 "UPDATE `$tables` SET `position` = '$posit', `left_right` = '$move_right' WHERE `id_top`='$id_'";
      
mysql_query($update2);
    }else{
      
set_position($tables$id_);

      
#$sql_num="SELECT count(*) FROM `$tables` WHERE left_right='$move_right'";
      
$sql_num "SELECT MAX(position) position FROM $tables WHERE left_right = '$move_right'";
      
$re_num mysql_query($sql_num);
      
$data_num mysql_fetch_array($re_num);
      
$posit $data_num[0] + 1;

      
$update "UPDATE `$tables` SET `position` = '$posit',`left_right` = '$move_right' WHERE `id_top`='$id_'";
      
// update table menu_top
      
mysql_query($update);
    }
//  }

  #echo "<meta http-equiv='refresh' content='0; url=index.php'>";
  
header"location: index.php?f=$id_);
  exit(
0);
}

//################## ###################
if ($id_del_top != "" and $module == "link") {
// find id_sub form id_del_top
  
$sql "SELECT id_sub FROM cms_menu_sub WHERE id_top='$id_del_top' order by id_sub asc";
  
$re mysql_query($sql);
  
$count_num mysql_num_rows($re);

  if (
$count_num 1) {
    while (
$data_id_sub mysql_fetch_array($re)) {

      
// cms_news_page
      
$sql1 "select id_sub,pic1,pic2,pic3,pic4,files from cms_news_page where id_sub='$data_id_sub[id_sub]'";
      
$result1 mysql_query($sql1);
      while (
$data1 mysql_fetch_array($result1)) {
        if (
$data1['pic1'] != "") {
          
unlink("$_SESSION[web_name]/mainfile/$data1[1]");
        }
        if (
$data1['pic2'] != "") {
          
unlink("$_SESSION[web_name]/mainfile/$data1[2]");
        }
        if (
$data1['pic3'] != "") {
          
unlink("$_SESSION[web_name]/mainfile/$data1[3]");
        }
        if (
$data1['pic4'] != "") {
          
unlink("$_SESSION[web_name]/mainfile/$data1[4]");
        }
        if (
$data1['files'] != "") {
          
unlink("$_SESSION[web_name]/mainfile/$data1[5]");
        }
        
$sql "delete from cms_news_page where id_sub='$data1[id_sub]'";
        
$result mysql_query($sql) or die(mysql_error());
      }

      
// cms_link
      
$sql_1 "SELECT id_group FROM cms_link_group WHERE id_sub='$data_id_sub[id_sub]'";
      
$re_1 mysql_query($sql_1);
      while (
$data_1 mysql_fetch_array($re_1)) {

        
$sql_2 "select id_link,picture from cms_link where id_group='$data_1[id_group]' order by id_link";
        
$re_2 mysql_query($sql_2);
        while (
$data_2 mysql_fetch_array($re_2)) {
          if (
$data_2['picture'] != "") {
            
unlink("$_SESSION[web_name]/mainfile/$data_2[picture]");
          }
          
$sql "DELETE FROM cms_link WHERE id_link=$data_2[id_link]";
          
$result mysql_query($sql);
        }
        
$sql_3 "DELETE FROM cms_link_group WHERE id_sub='$data_id_sub[id_sub]'";
        
$result_3 mysql_query($sql_3);
      }
      
// cms_blog
      
$sql_4 "DELETE FROM `cms_blog`  WHERE id_sub='$data_id_sub[id_sub]'";
      
$re_4 mysql_query($sql_4) or die(mysql_error());

      
// cms_faq
      
$sql "DELETE FROM `cms_faq`  WHERE id_sub='$data_id_sub[id_sub]'";
      
$re mysql_query($sql) or die(mysql_error());
    }

    
// cms_menu_sub
    
$sql "DELETE FROM cms_menu_sub WHERE id_top='$id_del_top'";
    
$result mysql_query($sql);
  }
  
  
set_position('cms_menu_top'$id_del_top);
  
//     cms_menu_top
  
$sql "DELETE FROM cms_menu_top WHERE id_top='$id_del_top'";
  
$result mysql_query($sql) or die(mysql_error());

  
#echo "<meta http-equiv='refresh' content='0; url=index.php'>";
  
header"location: index.php" );
  exit(
0);
}


//################## ###################
if ($id_del_top != "" and $module == "picture") {
  
//cms_link_picture 
  
$sql "SELECT id_pic ,pic_name FROM cms_link_picture WHERE id_top='$id_del_top'";
  
$re mysql_query($sql);
  while (
$data mysql_fetch_array($re)) {
    if (
$data['pic_name'] != "") {
      
unlink("$_SESSION[web_name]/module_picture/$data[pic_name]");
    }
    
$sql "delete from cms_link_picture where id_pic='$data[id_pic]'";
    
$result mysql_query($sql) or die(mysql_error());
  }
  
  
set_position('cms_menu_top'$id_del_top);
  
//     cms_menu_top
  
$sql "DELETE FROM cms_menu_top WHERE id_top='$id_del_top'";
  
$result mysql_query($sql) or die(mysql_error());

  
#echo "<meta http-equiv='refresh' content='0; url=index.php'>";
  
header"location: index.php" );
  exit(
0);
}

//################## ###################
if ($id_del_top != "" and $module == "sponser") {
  
//cms_link_picture 
  
$sql "SELECT id_sponser ,pic_name FROM cms_link_sponser WHERE id_top='$id_del_top'";
  
$re mysql_query($sql);
  while (
$data mysql_fetch_array($re)) {
    if (
$data[pic_name] != "") {
      
unlink("$_SESSION[web_name]/module_sponser/$data[pic_name]");
    }
    
$sql "delete from cms_link_sponser where id_sponser='$data[id_sponser]'";
    
$result mysql_query($sql) or die(mysql_error());
  }
  
  
set_position('cms_menu_top'$id_del_top);
  
//     cms_menu_top
  
$sql "DELETE FROM cms_menu_top WHERE id_top='$id_del_top'";
  
$result mysql_query($sql) or die(mysql_error());

  
#echo "<meta http-equiv='refresh' content='0; url=index.php'>";
  
header"location: index.php" );
  exit(
0);
}

//################## ###################
if ($id_del_top != "" and $module == "boss_message") {
  
//cms_link_picture 
  
$sql "SELECT id_message ,picture FROM cms_boss_message WHERE id_top='$id_del_top'";
  
$re mysql_query($sql);
  while (
$data mysql_fetch_array($re)) {
    if (
$data[picture] != "") {
      
unlink("$_SESSION[web_name]/module_boss_message/$data[picture]");
    }
    
$sql "delete from cms_boss_message where id_message='$data[id_message]'";
    
$result mysql_query($sql) or die(mysql_error());
  }
  
  
set_position('cms_menu_top'$id_del_top);
  
//     cms_menu_top
  
$sql "DELETE FROM cms_menu_top WHERE id_top='$id_del_top'";
  
$result mysql_query($sql) or die(mysql_error());

  
#echo "<meta http-equiv='refresh' content='0; url=index.php'>";
  
header"location: index.php" );
  exit(
0);
}

//################## CODE ###################
if ($id_del_top != "" and $module == "code") {
  
  
set_position('cms_menu_top'$id_del_top);
  
//     cms_code
  
$sql "DELETE FROM cms_menu_top WHERE id_top='$id_del_top'";
  
$result mysql_query($sql) or die(mysql_error());
  
$sql "DELETE FROM cms_code WHERE id_top='$id_del_top'";
  
$result mysql_query($sql) or die(mysql_error());

  
#echo "<meta http-equiv='refresh' content='0; url=index.php'>";
  
header"location: index.php" );
  exit(
0);
}

function 
set_position($table$id){
  
$sql "SELECT position, left_right FROM `$table` WHERE `id_top`='$id'";
  
$re mysql_query($sql);
  
$data mysql_fetch_array($re);
  
  
$sel "SELECT * FROM `$table` WHERE `position` > '$data[position]' AND left_right = '$data[left_right]' ORDER BY position";
  
$re mysql_query($sel);
  while (
$new mysql_fetch_array($re)) {
    
$position $new['position'] - 1;
    
$sql "UPDATE `$table` SET `position` = '$position' WHERE `id_top` ='$new[id_top]'";
    
mysql_query($sql);
  }
}
?>