/home/banprang/.trash/files/coremain.3/module/web/gallery/gallery_update.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
// Status Package Module
$status_module=select_query("status_module","cms_status_module","id","18");
if(
$status_module[0]!=1)    {    
    
fieldset_no_module();
}

$navig['gallery']="ภาพกิจกรรม";
$navig['gallery_add']="ภาพทั้งหมด";
navigator($navig);
echo 
"<br>";
bar_header("ภาพทั้งหมด");
fieldset_top("ภาพกิจกรรม");

import_request_variables('pG''p_');
include_once(
"coremain/module/gallery/class.upload.php");
if(
$p_g_type!="")                                                    {         $g_type=trim($p_g_type);                                    }
if(
$p_id_update!="")                                                {         $id_update=trim($p_id_update);                        }
if(
$p_yearthai1!="")                                                {         $yearthai1=trim($p_yearthai1);                            }
if(
$p_id_hide!="")                                                    {         $id_hide=trim($p_id_hide);                                    }
if(
$p_id_show!="")                                                {         $id_show=trim($p_id_show);                                }
if(
$p_id_del!="")                                                    {         $id_del=trim($p_id_del);                                        }
if(
$p_block!="")                                                        {         $block=trim($p_block);                                        }


//###################### สำหรับ Admin
if($_SESSION[admin_web]=="admin" or (id_top_permission("b"))){
// Hide - Show port_gallery_record
        
if($id_hide!=""){
            
$sql="UPDATE port_gallery_record SET status='0'  WHERE id_record='$id_hide'";
            
mysql_query($sql);        
        }
        if(
$id_show!=""){
            
$sql="UPDATE port_gallery_record SET status='1'  WHERE id_record='$id_show'";
            
mysql_query($sql);
        }
// Delete port_gallery_record
        
if($id_del!=""){
            
// delete port_gallery_record
            
$sql="SELECT pic FROM port_gallery_record WHERE id_record='$id_del'";
            
$result=mysql_query($sql);
            while(
$data=mysql_fetch_array($result)){
                    if(
$data[0]!="")        {            unlink("$_SESSION[web_name]/gallery/$data[0]");     unlink("$_SESSION[web_name]/gallery/thumb/$data[0]");    }
            }
            
$sql "delete from port_gallery_record  where id_record='$id_del'";
            
$result mysql_query($sql);
        }

if(
$p_hiddata!="")                            {  $hiddata=trim($p_hiddata);                                            }
$num "'";
$hiddata ereg_replace('"'$num$hiddata);

// Update
if($hiddata!=""){
$sql="UPDATE `port_gallery_topic` SET fulltexts ='$hiddata' ,'en_fulltexts'='$hiddata2' WHERE id_topic='$id_update'";
$result=mysql_query($sql);
}

//  ################Upload Picture เพิ่มเติม #########################
if($p_upload_pic!="")                        {         $upload_pic=trim($p_upload_pic);        }
if(
$p_explain!="")                                {         $explain=trim($p_explain);                    }
if(
$p_en_explain!="")                                {         $en_explain=trim($p_en_explain);                    }
$userfile1_name=trim($_FILES['userfile1']['name']);
if(
$userfile1_name!=""){
        
$strings1=substr($userfile1_name,-4);
            if(
$strings1!=".gif" and $strings1!=".jpg" and $strings1!=".GIF" and $strings1!=".JPG"){
                    echo
"<center><br>ชนิดไฟล์ไม่ถูกต้อง <br>ไฟล์ต้องมีนามสกุลเป็น .gif หรือ .jpg เท่านั้น<br><br>";
                    echo
"<a href='javascript:history.back()'><font color='ff0000'>[แก้ไขใหม่]</font></center></a>";
                    exit;
            }
}
if(
$userfile1_name!="")
{
         
// กำหนดชื่อไฟล์ที่ upload ใหม่ ทั้งนี้เพื่อให้ ไฟล์ไม่ซ้ำกัน
        
$sqlmax1="select max(id_record+1)  from port_gallery_record";
        
$resultmax1=mysql_query($sqlmax1);
        
$datamax1=mysql_fetch_row($resultmax1);
        
$str  "23456789abcdefghijkmnpqrstuvwxyz";
        
$pic substr(str_shuffle($str), 05);
        
// ชื่อไฟล์
        
$strings=substr($userfile1_name,-4);
        
$strings strtolower($strings);
        
$name1="pic$pic$datamax1[0]$strings";
        
$dlink="gallery/".$name1;
/*        $temp_name=$_FILES['userfile1']['tmp_name'];
        if (is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
        if(!move_uploaded_file($temp_name,$dlink)){                        }                    }*/
        
$hup = new upload($_FILES['userfile1']);
        if(
$hup->uploaded){
            
$hup->image_resize true;
            
$hup->image_y  400;
            
$hup->image_x 640;
            
$hup->image_ratio true;
            
$hup->image_ratio_no_zoom_in true;
            
$hup->jpeg_quality 95;
            
$hup->file_new_name_body "pic{$pic}{$datamax1[0]}";
            
$hup->Process("$_SESSION[web_name]/gallery/");
            if(
$hup->processed){

            }else{
                
//echo 'failed';
            
}
            
$hup->image_resize true;
            
$hup->image_y  100;
            
$hup->image_x 150;
            
$hup->image_ratio true;            
            
$hup->jpeg_quality 95;
            
$hup->image_ratio_no_zoom_in true;            
            
$hup->file_new_name_body "pic{$pic}{$datamax1[0]}";            
            
$hup->Process("$_SESSION[web_name]/gallery/thumb/");
            if(
$hup->processed){
                
//echo 'success2';
                
chmod("$_SESSION[web_name]/gallery/thumb/{$name1}",0777);                
            }else{
                echo 
'failed';
            }            
        }        
}
// ########### Add ข้อมูลลงใน Record
if($userfile1_name!=""){
        
// หาค่า id สูงสุด + 1
        
$sqlmax1="select max(id_record+1) from port_gallery_record";
        
$resultmax1=mysql_query($sqlmax1);
        
$datamax1=mysql_fetch_row($resultmax1);        if ($datamax1[0]=="")        {            $datamax1[0]="1";        }

        
$sql "INSERT INTO port_gallery_record values('$datamax1[0]','$id_update','$name1','$explain','$en_explain','1')";
        
$result mysql_query($sql) or die(mysql_error());
}
}

// ################################ภาพกิจกรรม ###################################
$sql="SELECT * FROM `port_gallery_topic`  WHERE  id_topic='$id_update'"
$result=mysql_query($sql);
$data mysql_fetch_array($result);

echo 
"$data[fulltexts]";    


 
// เพิ่มรูปภาพกิจกรรม 
if($_SESSION[admin_web]=="admin" or (id_top_permission("b"))){
echo
"<form  action='index.php?id_update=$id_update&mod=gallery_update&path=gallery&id_hide=$data[id_record]&block=$block' method='post' enctype='multipart/form-data' name='add' id='add' onSubmit='return checkadd()'>";
echo
"<table width='98%' border='0' align='center' cellpadding='1' cellspacing='1'>";
    echo
"   <tr>";
    echo
"     <td colspan='2' align='center'><b>Upload รูปเพิ่มเติม</b><br><br></td> ";
    echo
"  </tr>";

    echo
"   <tr>";
    echo
"     <td width='22%' align=center><img src='coremain/images/marker.gif'>  <strong>Upload รูป</strong></td> ";
    echo
"     <td><input name='userfile1' type='file' size='40'> &nbsp; <img src='coremain/images/bu.gif' border='0' title='รูปควรมีขนาดประมาณ 400*300 Pixel' onmouseover=this.style.cursor='hand'>";
    echo
"    </td> ";
    echo
"  </tr>";
    
    echo
"   <tr>";
    echo
"     <td align=center><img src='coremain/images/marker.gif'> <strong> คำอธิบายรูป &nbsp;  &nbsp; </strong></td> ";
    echo
"     <td><input name='explain' type='text' size='40' >";
    echo 
"<INPUT TYPE='hidden' name='check_upload' value='1'>";
    echo
"    </td> ";
    echo
"  </tr>";    


    echo
"<tr>      ";
    echo
"     <td colspan=2 align=center><br>       ";
    echo
"<input type='submit' name='upload_pic' value='Upload รูป' onmouseover=this.style.cursor='hand'>";
    echo
"</td>"
    echo
"  </tr>";

echo 
"</table>";
echo 
"</form>";
 }

echo
"<table width='97%' border='0' cellpadding='0' cellspacing='0' align=center>";
if(
$_SESSION[admin_web]=="admin" or (id_top_permission("b")))    $sql="SELECT * FROM `port_gallery_record`  WHERE  id_topic='$id_update'";
else                                                            
$sql="SELECT * FROM `port_gallery_record`  WHERE  id_topic='$id_update' and status='1'";
$result=mysql_query($sql);
$count=2;
while(
$data mysql_fetch_array($result)){
$count++;   $mots=$count%3;
    
//###################### คอลัมน์ที่ 1 ###############
    
if($mots==0){
        echo 
"<tr>";
        echo 
"<td width=33% align=center>";
                 echo
"<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 align='center'>";
                 echo
"     <TR> ";
                 echo
"       <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_01.gif' WIDTH=15 HEIGHT=15 ALT='' border='0'></TD>";
             echo
"       <TD valign='top' background='coremain/images/border/popup_border_02.gif' border='0'></TD>";
            echo
"        <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_03.gif' WIDTH=17 HEIGHT=15 ALT='' border='0'></TD>";
             echo
"     </TR>";
             echo
"     <TR> ";
              echo
"      <TD valign='top' background='coremain/images/border/popup_border_04.gif' border='0'> </TD>";
?>                 
<TD valign='top'><a href="#WIN" onClick="window.open('coremain/module/gallery/gallery_show.php?pic=<?php echo $data[pic];?>&web_name=<?php echo $_SESSION[dbname]?>&id_topic=<?echo $id_update;?>&id_record=<?echo $data[id_record]?>&id_top=<?echo $id_update;?>&folder=<?echo $_SESSION[web_name];?>','blah2','width=700,height=500,location=0,menubar=0,toolbar=0,scrollbars=yes,resizable=yes')"><img src='<?php echo "$_SESSION[web_name]/gallery/thumb/$data[pic]";?>' border='0'></a></TD>
<?php
                  
echo"       <TD valign='top' background='coremain/images/border/popup_border_06.gif' border='0'></TD>";
            echo
"      </TR>";

            echo
"      <TR> ";
            echo
"        <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_07.gif' WIDTH=15 HEIGHT=16 ALT='' border='0'></TD>";
             echo
"       <TD valign='top' background='coremain/images/border/popup_border_08.gif' border='0'> </TD>";
             echo
"       <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_09.gif' WIDTH=17 HEIGHT=16 ALT='' border='0'></TD>";
                 echo
"      </TR>";
                 echo
"  </TABLE>";
                 if(
$data[explain]!="")                
                      echo 
$data[explain];
                      else                                            
                      echo 
"&nbsp;";
                
if(
$_SESSION[admin_web]=="admin" or (id_top_permission("b"))){
            
// show - hide
            
if($data[status]=='1'){
                echo 
"<br><a href='index.php?id_update=$id_update&mod=gallery_update&path=gallery&id_hide=$data[id_record]&block=$block'><img src='coremain/images/show.gif' border='0' title='ซ่อน'></a>";    
            }else{    
                echo 
"<br><a href='index.php?id_update=$id_update&mod=gallery_update&path=gallery&id_show=$data[id_record]&block=$block'><img src='coremain/images/hide.gif' border='0' title='แสดง'></a>";
            }
            
// delete
                
echo " &nbsp;<a href='index.php?id_update=$id_update&mod=gallery_update&path=gallery&id_del=$data[id_record]&block=$block' onclick='return goURL();'><img src='coremain/images/del1.gif' border='0' title='ลบข้อมูล'></a>";    
}
        echo
"</td>";
    }
    
//###################### คอลัมน์ที่ 2 ###############    
    
else if($mots==1){
        echo 
"<td width=33% align=center>";
                 echo
"<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 align='center'>";
                 echo
"     <TR> ";
                 echo
"       <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_01.gif' WIDTH=15 HEIGHT=15 ALT='' border='0'></TD>";
             echo
"       <TD valign='top' background='coremain/images/border/popup_border_02.gif' border='0'></TD>";
            echo
"        <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_03.gif' WIDTH=17 HEIGHT=15 ALT='' border='0'></TD>";
             echo
"     </TR>";
             echo
"     <TR> ";
              echo
"      <TD valign='top' background='coremain/images/border/popup_border_04.gif' border='0'> </TD>";
?>                 
<TD valign='top'><a href="#WIN" onClick="window.open('coremain/module/gallery/gallery_show.php?pic=<?php echo $data[pic];?>&web_name=<?php echo $_SESSION[dbname];?>&id_top=<?echo $id_update;?>&folder=<?echo $_SESSION[web_name];?>','blah2','width=700,height=500,location=0,menubar=0,toolbar=0,scrollbars=yes,resizable=yes')"><img src='<?php echo "$_SESSION[web_name]/gallery/thumb/$data[pic]";?>' border='0'></a></TD>
<?php
                  
echo"       <TD valign='top' background='coremain/images/border/popup_border_06.gif' border='0'></TD>";
            echo
"      </TR>";

            echo
"      <TR> ";
            echo
"        <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_07.gif' WIDTH=15 HEIGHT=16 ALT='' border='0'></TD>";
             echo
"       <TD valign='top' background='coremain/images/border/popup_border_08.gif' border='0'> </TD>";
             echo
"       <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_09.gif' WIDTH=17 HEIGHT=16 ALT='' border='0'></TD>";
                 echo
"      </TR>";
                 echo
"  </TABLE>";
                 if(
$data[explain]!="")                
                      echo 
$data[explain];
                      else                                            
                      echo 
"&nbsp;";
// Admin
if($_SESSION[admin_web]=="admin" or (id_top_permission("b"))){
            
// show - hide
            
if($data[status]=='1'){
                echo 
"<br><a href='index.php?id_update=$id_update&mod=gallery_update&path=gallery&id_hide=$data[id_record]&block=$block'><img src='coremain/images/show.gif' border='0' title='ซ่อน'></a>";    
            }else{    
                echo 
"<br><a href='index.php?id_update=$id_update&mod=gallery_update&path=gallery&id_show=$data[id_record]&block=$block'><img src='coremain/images/hide.gif' border='0' title='แสดง'></a>";
            }
            
// delete
                
echo " &nbsp;<a href='index.php?id_update=$id_update&mod=gallery_update&path=gallery&id_del=$data[id_record]&block=$block' onclick='return goURL();'><img src='coremain/images/del1.gif' border='0' title='ลบข้อมูล'></a>";    
}
        echo
"</td>";
    }
    
//###################### คอลัมน์ที่ 3 ###############    
    
else{
        echo 
"<td width=33% align=center>";
                 echo
"<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 align='center'>";
                 echo
"     <TR> ";
             echo
"       <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_01.gif' WIDTH=15 HEIGHT=15 ALT='' border='0'></TD>";
             echo
"       <TD valign='top' background='coremain/images/border/popup_border_02.gif' border='0'></TD>";
            echo
"        <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_03.gif' WIDTH=17 HEIGHT=15 ALT='' border='0'></TD>";
             echo
"     </TR>";
             echo
"     <TR> ";
              echo
"      <TD valign='top' background='coremain/images/border/popup_border_04.gif' border='0'> </TD>";
?>                 
<TD valign='top'><a href="#WIN" onClick="window.open('coremain/module/gallery/gallery_show.php?pic=<?php echo $data[pic];?>&web_name=<?php echo $_SESSION[dbname];?>&id_top=<?echo $id_update;?>&folder=<?echo $_SESSION[web_name];?>','blah2','width=700,height=500,location=0,menubar=0,toolbar=0,scrollbars=yes,resizable=yes')"><img src='<?php echo "$_SESSION[web_name]/gallery/thumb/$data[pic]";?>' border='0'></a></TD>
<?php
                  
echo"       <TD valign='top' background='coremain/images/border/popup_border_06.gif' border='0'></TD>";
            echo
"      </TR>";

            echo
"      <TR> ";
            echo
"        <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_07.gif' WIDTH=15 HEIGHT=16 ALT='' border='0'></TD>";
             echo
"       <TD valign='top' background='coremain/images/border/popup_border_08.gif' border='0'> </TD>";
             echo
"       <TD valign='top'> <IMG SRC='coremain/images/border/popup_border_09.gif' WIDTH=17 HEIGHT=16 ALT='' border='0'></TD>";
                 echo
"      </TR>";
                 echo
"  </TABLE>";
                
                 if(
$data[explain]!="")                
                      echo 
$data[explain];
                      else                                            
                      echo 
"&nbsp;";
            
// Admin
if($_SESSION[admin_web]=="admin" or (id_top_permission("b"))){
            
// show - hide
            
if($data[status]=='1'){
                echo 
"<br><a href='index.php?id_update=$id_update&mod=gallery_update&path=gallery&id_hide=$data[id_record]&block=$block'><img src='coremain/images/show.gif' border='0' title='ซ่อน'></a>";    
            }else{    
                echo 
"<br><a href='index.php?id_update=$id_update&mod=gallery_update&path=gallery&id_show=$data[id_record]&block=$block'><img src='coremain/images/hide.gif' border='0' title='แสดง'></a>";
            }
            
// delete
            
echo " &nbsp;<a href='index.php?id_update=$id_update&mod=gallery_update&path=gallery&id_del=$data[id_record]&block=$block' onclick='return goURL();'><img src='coremain/images/del1.gif' border='0' title='ลบข้อมูล'></a>";    
}
        echo
"</td>";
        echo 
"</tr>";
        echo 
"<tr height='20'><td></td><td></td></tr>";
    }

}
echo 
"</table>";

fieldset_down();
?>


<script language="JavaScript">
<!--
function goURL() {
var blnLink
blnLink = confirm("Click OK เพื่อยืนยันการลบข้อมูล?")
if (!blnLink) { return false; }
return true;
}
//-->    
</script>

<script language="javascript">
function checkadd() {
if(document.add.userfile1.value=="") {
alert("กรุณาเลือกรูปที่จะอัพโหลด") ;
document.add.userfile1.focus() ;
return false ;}
else 
return true ;
}
</script>