/home/banprang/domains/plai.go.th/public_html/coremain/module/gallery/gallery_edit_pic.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
<?php
// Status Package Module
$status_module=select_query("status_module","cms_status_module","id","18");
if(
$status_module[0]!=1)    {    
    
fieldset_no_module();
}
// Pession
if(id_top_permission("b")!=1){    
    
permission_fail();            
}
check_status();
echo
"<table width='98%' border='0' cellpadding='0' cellspacing='0'>";
echo
"  <tr >";
echo
"    <td><div class='c_header'>รูปภาพ</div></td>";
echo
"  </tr>";
echo
"  <tr>";
echo
"    <td><div class='c_body'>";

session_start();
//include("../../function.php");
//admin_web_activity("index.php");
echo"<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
include(
"../../../$_SESSION[webname]/connect.php");

echo 
"<title>แก้ไขรูปภาพ</title>";
$sqltm="select * from main_themes where status='1'";
$resulttm=mysql_query($sqltm);
$datatm=mysql_fetch_array($resulttm);
echo 
"<body bgcolor='$datatm[navigrator]'>";

import_request_variables('pG''p_');
if(
$p_update_pic!="")                                {         $update_pic=trim($p_update_pic);            }
if(
$p_id_record!="")                                    {         $id_record=trim($p_id_record);            }
$userfile1_name=trim($_FILES['userfile1']['name']);
if(
$p_explain!="")                                {         $explain=trim($p_explain);                    }
if(
$p_post_pic!="")                            {         $post_pic=trim($p_post_pic);            }
if(
$p_id_update!="")                            {         $id_update=trim($p_id_update);        }
if(
$p_g_type!="")                                                    {         $g_type=trim($p_g_type);                                }
if(
$p_yearthai1!="")                                                    {         $yearthai1=trim($p_yearthai1);                            }

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>";
                    include(
'coremain/fieldset_bottom.php');    
                    include(
'coremain/footer.php');
                    exit;
            }
}
//************** ตรวจสอบว่า มีการ Upload File หรือไม************่
if($userfile1_name!="")
{     
// กำหนดชื่อไฟล์ที่ upload ใหม่ ทั้งนี้เพื่อให้ ไฟล์ไม่ซ้ำกัน
        
$str  "23456789abcdefghijkmnpqrstuvwxyz";
        
$pic substr(str_shuffle($str), 05);
        
// ลบไฟล์เก่าออกก่อน    
        
$sql1="select pic from cms_gallery_record where id_record='$id_record'";
        
$result1=mysql_query($sql1);
        
$data1=mysql_fetch_row($result1);
        if(
$data1[0]!="")        {            unlink("../../../$_SESSION[webname]/mainfile/gallery/pic/$data1[0]");        }        
        
// ชื่อไฟล์
        
$strings=substr($userfile1_name,-4);
        
$name1="uppic$pic$strings";
                    
$dlink="../../../$_SESSION[webname]/mainfile/gallery/pic/".$name1;
                    
$temp_name=$_FILES['userfile1']['tmp_name'];
                    if (
is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
                        if(!
move_uploaded_file($temp_name,$dlink)){                        }                    }
}

if(
$post_pic=="1"){
    
$sql="select pic from `cms_gallery_record` where id_record='$id_record'";
    
$result=mysql_query($sql);
    
$data=mysql_fetch_row($result);
    if(
$userfile1_name=="")    {        $name1=$data[0];    }

    
$sql="UPDATE `cms_gallery_record`  SET  `pic`='$name1', `explain` = '$explain' WHERE `id_record` ='$id_record'";
    
$result=mysql_query($sql);
?>
<script language="JavaScript"> 
    window.opener.location.href='../../../index.php?link1=gallery&id_record=<?echo $id_topic?>&link=gallery_update&g_type=<?echo $g_type?>&yearthai1=<?echo $yearthai1?>&id_update=<?echo $id_update?>';
    window.close();
</script>
<?php
}
echo 
"<fieldset><legend>แก้ไขรูปภาพ</legend>";
if(
$update_pic=="1")
{
$sql="SELECT * FROM `cms_gallery_record`  WHERE  id_record='$id_record'";
$result=mysql_query($sql);
$data mysql_fetch_array($result);
echo 
"<form  action='gallery_edit_pic.php?id_record=$id_record&id_update=$id_update&year_thai=$yearthai1&g_type=$g_type' method='post' enctype='multipart/form-data' name='add'>";
echo 
"<table width='540' border='0' align='center' cellpadding='1' cellspacing='3'>";

echo 
"    <tr>";
echo 
"     <td width=30%><div align='left'><strong>แก้ไขรูปภาพ</strong></div></td><td width=70%><div align='left'><input name='userfile1' type='file' size='35'> &nbsp; <img src='../../../coremain/image/bu.gif' border='0' title='รูปควรมีขนาดประมาณ 400*300 Pixel' onmouseover=this.style.cursor='hand'></td> ";
echo 
"  </tr>";

echo 
"    <tr>";
echo 
"     <td width=30%><div align='left'><strong>คำอธิบายรูป</strong></div></td><td width=70%><div align='left'><input name='explain' type='text' size='35' value=$data[explain]></td> ";
echo 
"  </tr>";

echo 
"<tr>";
echo 
"       <td width=25%><div align='left'></div></td> ";
echo 
"<INPUT TYPE='hidden' name='post_pic' value='1'>";
echo 
"       <td width=70%><div align='left'>         ";        
echo 
"               <input type='submit' name='Submit' value='   แก้ไข   ' onmouseover=this.style.cursor='hand'>";

echo 
"               <input type='submit' name='Submit2' value='ปิดหน้านี้' onclick='window.close()'></td> ";
echo 
"</tr>";
echo 
"</table>";
echo 
"</form> ";
}
echo
" </div></td>";
echo
"  </tr>";

echo
"  <tr>";
echo
"    <td><div class='c_footer'></div></td>";
echo
"  </tr>";
echo 
"</table>";
?>