/home/banprang/domains/plai.go.th/public_html/coremain/module/director_chart/director_chart.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
<?php
/************************************************************************
*  director_chart.php
*  Show chart by arrange column and row order 
*
*  @author pandarianz
*  Email pandarianz@gmail.com
*************************************************************************/
import_request_variables('pG''p_');
if(
$p_id_sub!="")            {  $id_sub=trim($p_id_sub);                        }
if(
$p_id_chart!="")            {  $id_chart=trim($p_id_chart);                    }
if(
$p_id_1!="")                {  $id_1=trim($p_id_1);                                    }
if(
$p_id_order1st!="")        {  $id_order1st=trim($p_id_order1st);                }
if(
$p_id_del_chart!="")    {  $id_del_chart=trim($p_id_del_chart);    }


// ###############UP & DOWN #################
if ($id_1 != "" && $id_order1st != "") {
  
$sql "SELECT * FROM cms_director_chart WHERE id_chart='$id_1'";
  
$re mysql_query($sql);
  
$data mysql_fetch_array($re);
  if (
$id_order1st == 1) {
    
$up $data['row_count'] - 1;
  }
  if (
$id_order1st == 2) {
    
$up $data['row_count'] + 1;
  }
  
// 
  
$sql "UPDATE cms_director_chart SET row_count='$up' WHERE id_chart='$data[id_chart]' and id_sub='$id_sub'";
  
$re mysql_query($sql);
  
// 
  
$sql "UPDATE cms_director_chart SET row_count='$data[row_count]'  WHERE id_chart !='$data[id_chart]' and row_count='$up' and id_sub='$id_sub'";
  
$re mysql_query($sql);
}
// ##################### DEL ROWS ALL ################
if ($id_del_chart != "") {
  
$sql "SELECT picture FROM cms_director_chart_profile WHERE id_chart='$id_del_chart'";
  
$re mysql_query($sql);
  while (
$data mysql_fetch_array($re)) {
    if (
$data[0] != "" && file_exists("$_SESSION[web_name]/module_chart/$id_sub/$data[0]")) {
      
unlink("$_SESSION[web_name]/module_chart/$id_sub/$data[0]");
    }
  }
  
$sql "DELETE FROM cms_director_chart_profile WHERE id_chart='$id_del_chart'";
  
$result mysql_query($sql);

  
$sql "DELETE FROM cms_director_chart WHERE id_chart='$id_del_chart' and id_sub='$id_sub'";
  
$result mysql_query($sql);
}

// ###################################################
if ($p_id_sub != "") {
  
$id_top trim($p_id_sub);
}
if (
$p_id_chart != "") {
  
$id_chart trim($p_id_chart);
}
if (
$p_header_change != "") {
  
$header_change trim($p_header_change);
}
// ส่วนจัดการ สำหรับ admin เท่านั้น
if ($_SESSION['admin_web'] == "admin" || id_sub_permission($id_sub) == 1) {
  
// เพิ่มแถวหลักใหม่
  
if ($_GET['add_row']) {
    
$max_row_count select_max_query("row_count""cms_director_chart""id_sub"$id_sub);
    if (
$max_row_count[0] == "")
      
$max_row_count[0] = 0;
    
$sql "INSERT INTO cms_director_chart (id_sub,row_count) values ($id_sub," $max_row_count[0] . ")";
    
query($sql);
  }

  
// แก้ไขหัว
  
if(isset($_POST['btn_edit_header'])){//if ($_POST['btn_edit_header']) {
    
$sql "UPDATE cms_director_chart SET header_text = '$header_change' WHERE id_sub=$id_sub";
    
query($sql);
  }
  
// ซ่อน แสดงผล
  
if ($_GET['status'] != "") {
    
$sql "UPDATE cms_director_chart_profile SET status = $_GET[status] WHERE id_profile = $_GET[profile]";
    
query($sql);
  }

  if (
$_GET['delete']) {
    
$sql "SELECT picture FROM cms_director_chart_profile WHERE id_profile = $_GET[profile]";
    
$re mysql_query($sql);
    
$data mysql_fetch_array($re);
    if (
$data[0] != "") {
      
unlink("$_SESSION[web_name]/module_chart/$id_sub/$data[0]");
    }
    
$sql "DELETE FROM  cms_director_chart_profile WHERE id_profile = $_GET[profile]";
    
query($sql);
  }

  if (
$_GET['row']) {
    
$sql "DELETE FROM  cms_director_chart WHERE row_count = $_GET[row] and id_sub = $id_sub";
    
query($sql);
  }
}
$count_xx 1;

$navig['link_picture'] = $data_name_menu_sub['name'];
navigator($navig);
echo 
"<br>";
bar_header("$data_name_menu_sub[name]"); // Bar_Header
fieldset_top($data_name_menu_sub['name']);
// header info

$dat_info select_query_object("header_text""cms_director_chart""id_sub"$id_sub" and header_text!=''");
$header_info $dat_info->header_text;


echo 
"<center>";
if (
$_SESSION['admin_web'] == "admin" || id_sub_permission($id_sub) == 1) {
  echo 
"<form name='header_form' method='post' action='index.php?mod=director_chart&path=director_chart&id_sub=$id_sub'>";
  echo 
print_arr1();
  echo 
" <b>แก้ไขส่วนหัว</b> : <input type='text' name='header_change' value='$header_info'>";
  
button_text('แก้ไข''btn_edit_header'0);
  
#text_button_update();
//  echo "&nbsp;&nbsp;<input type='submit' name='btn_edit_header' value='แก้ไข'>";
  
echo "</form>";
} else {
  echo 
"<b>$header_info </b>";
}

echo 
"</center>";

// query sturcture table
$sql "SELECT * FROM cms_director_chart WHERE id_sub = $id_sub group by row_count";
$res query($sql);
while (
$struct_table mysql_fetch_array($res)) {
  
// get result column number for get table width percent

  
$sql_count "SELECT COUNT(*) as numcount FROM cms_director_chart_profile as d1 inner join cms_director_chart as d2 on (d1.id_chart = d2.id_chart and d2.id_sub = $id_sub and d1.id_chart =$struct_table[id_chart])";
  
$res_count query($sql_count);
  
$dat_count mysql_fetch_object($res_count);
  
$count_col $dat_count->numcount;
  if (
$count_col != 0)
    
$width_table 100 $count_col;
  else
    
$width_table 100;

  echo 
"<table width='98%' border='0'>";
  echo 
"<tr>";
  if (
$_SESSION['admin_web'] == "admin" || id_sub_permission($id_sub) == 1// แยกการมองเห็น ตามสถานะ
    
$sql "SELECT * FROM cms_director_chart_profile WHERE  id_chart =" $struct_table["id_chart"];
  else
    
$sql "SELECT * FROM cms_director_chart_profile WHERE  id_chart =" $struct_table["id_chart"] . " and status=1";
  
$res_col query($sql);
  if (
$count_col == && ( $_SESSION['admin_web'] == "admin" || id_sub_permission($id_sub) == 1)) {
    echo 
"<td align='center' width='$width_table%'>";
    
print_nopic();
    echo 
"</td>";
  }
  while (
$data_col mysql_fetch_array($res_col)) {

    echo 
"<td align='center' width='$width_table%'>";
    if (
$_SESSION['admin_web'] == "admin" || id_sub_permission($id_sub) == 1) {
      echo 
"<br/>";

      if (
$data_col['status'] == 1)
        
box_hide("index.php?mod=director_chart&path=director_chart&id_sub=$id_sub&profile=$data_col[id_profile]&status=0");
      else
        
box_show("index.php?mod=director_chart&path=director_chart&id_sub=$id_sub&profile=$data_col[id_profile]&status=1");

      
box_update("index.php?mod=director_edit_profile&path=director_chart&id_profile=$data_col[id_profile]&id_sub=$id_sub&id_chart=$struct_table[id_chart]");
      
box_delete("index.php?mod=director_chart&path=director_chart&id_sub=$id_sub&profile=$data_col[id_profile]&delete=1""del_confirm");
      echo 
"<br/>";
    }
    if (
file_exists($_SESSION['web_name'] . "/module_chart/$id_sub/$data_col[picture]")) {
      echo 
"<a href='index.php?mod=personel_profile&path=director_chart&id_sub=$id_sub&id_profile=$data_col[id_profile]'>";
      echo 
"<img src='" $_SESSION['web_name'] . "/module_chart/$id_sub/$data_col[picture]' border='0'>"// show image
      
echo "</a>";
      
// profile

      
echo "<br/>";
      echo 
"<br/><b>";
      echo 
$data_col["name"];
      echo 
"</b><br/><b><font color='ff9900'>";
      echo 
$data_col["position"];
      echo 
"</font></b><br/>";

      if(
$data_col[telephone]!=""){
    echo 
"<b>โทรศัพท์ :</b> $data_col[telephone]";
    echo 
"<br/>"; }



    } else
      
print_nopic();
    echo 
"</td>";
  }
  echo 
"</tr>";
  echo 
"</table>";

  if (
$_SESSION['admin_web'] == "admin" || id_sub_permission($id_sub) == 1) {
    echo 
"<table align='center' width='98%'>";
    echo 
"<tr>";
    echo 
"<td align='right'>";
    echo 
"<a href='index.php?mod=director_add&path=director_chart&id_sub=$id_sub&id_chart=" $struct_table['id_chart'] . "'>";
    
print_arr_add();
    echo 
"เพิ่มข้อมูลในแถวนี้";
    echo 
"</a>&nbsp;";

    
$sql_num "SELECT count(*) FROM cms_director_chart WHERE id_sub='$id_sub'";
    
$re_num mysql_query($sql_num);
    
$data_num1 mysql_fetch_array($re_num);
    
// UP
    
if ($count_xx 1) {
      echo 
"<a href='index.php?mod=director_chart&path=director_chart&id_sub=$id_sub&id_type=$id_type&id_1=$struct_table[id_chart]&id_order1st=1'>";
      echo 
"<img src='coremain/images/up.gif' border=0></a>";
      echo 
"&nbsp;&nbsp;";
    } else {
      echo 
"&nbsp;&nbsp;";
    }
    
// DOWN
    
if ($count_xx $data_num1[0]) {
      echo 
"<a href='index.php?mod=director_chart&path=director_chart&id_sub=$id_sub&id_type=$id_type&id_1=$struct_table[id_chart]&id_order1st=2'>";
      echo 
"<img src='coremain/images/down.gif' border=0></a>";
    } else {
      echo 
"&nbsp;&nbsp;";
    }
    
// DEL
    
echo "&nbsp; <a href='index.php?mod=director_chart&path=director_chart&id_sub=$id_sub&id_type=$id_type&id_del_chart=$struct_table[id_chart]'><img src='coremain/images/del1.gif' border='0' title='ลบข้อมูล'  onclick='return goURLdel();'></a>";

    
$count_xx++;
    echo 
"<td>";
    echo 
"</tr>";
    echo 
"</table>";
    echo 
"<hr/>";
  }
}


// ส่วนปุ่มกดเพื่อเพิ่มแถว
if ($_SESSION['admin_web'] == "admin" || id_sub_permission($id_sub) == 1) {
  echo 
"<table width='98%'>";
  echo 
"<tr>";
  echo 
"<td align='center'>";
  echo 
"<a href='index.php?mod=director_chart&path=director_chart&id_sub=$id_sub&add_row=1'>";
  
print_arr_add();
  echo 
"เพิ่มแถวข้อมูล";
  echo 
"</a>";
  echo 
"</td>";
  echo 
"</td>";
  echo 
"</table>";
}
fieldset_down();
?>
<script language="javascript">
    function del_confirm(){
        return confirm("ต้องการลบบุคคลนี้ใช่หรือไม่");
    }
    function del_row(){
        return confirm("ต้องการลบแถวนี้ใช่หรือไม่ ประวัติทุกคนในแถวนี้จะถูกดำเนินการลบไปด้วย");
    }
</script>