/home/bjcompany/domains/benjabhorn.com/public_html/benjabhorn_group/control/hot_newsAdd.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
<?php
            $monthArray 
= array("01"=>"มกราคม","02"=>"กุมภาพันธ์","03"=>"มีนาคม","04"=>"เมษายน""05"=>"พฤษภาคม","06"=>"มิถุนายน","07"=>"กรกฏาคม","08"=>"สิงหาคม","09"=>"กันยายน","10"=>"ตุลาคม","11"=>"พฤศจิกายน","12"=>"ธันวาคม");    
        
$currentDate=date("d");
        
$currentMonthdate("m");
        
$currentMonthnamedate("m");            
        
$currentYeardate("Y");    
            
//------------------------------------------------------------------------
            
if($_GET['currentID']){
                    
$_POST['currentID']=$_GET['currentID'];
            }
            
//-----------------------------Date------------------------------------
            
setlocale (LC_TIME'th');
            
            if(!
$sdate) { $sdatestrftime("%Y-%m-%d"); }else{ $sdate=$sdate; }
            
$time=strftime("%H:%M:%S");
            
$time_sec=explode(":",$time);
            
$time_array explode(":",$time);    
        
####################################################
        
if($_POST['action']=='Delete'){
                 if(
file_exists($path_product."/".$_POST['RmPic'])){
                             @
unlink ($path_product."/".$_POST['RmPic']);
                 }
                   
$query="DELETE FROM tbl_act3_video WHERE id = '".$_POST['dataID']."' ";
                      
mysql_query($query);
        }
        
####################################################
            
if($_POST['action']=='deletePic'){
                 if(
file_exists($path_product."/thb/".$_POST['RmPic'])){
                             @
unlink ($path_product."/thb/".$_POST['RmPic']);
                 }
                 if(
file_exists($path_product."/".$_POST['RmPic'])){
                             @
unlink ($path_product."/".$_POST['RmPic']);
                 }
                 
$query "DELETE FROM  tbl_act3_pic WHERE  pic_name = '".$_POST['RmPic']."' ";
                 
mysql_query($query);
            }
        
####################################################
            
if($_POST['action']=='deleteDoc'){
                 if(
file_exists($path_product."/".$_POST['RmPic'])){
                             @
unlink ($path_product."/".$_POST['RmPic']);
                 }
                 
$query "DELETE FROM  tbl_act3_doc WHERE  pic_name = '".$_POST['RmPic']."' ";
                 
mysql_query($query);
            }            
        
####################################################checkInDay.checkInMonth.checkInYear
        
if($_POST['action']=='Add'){
                    
$dateAdddate("Y-d-m");
                     
$_POST['product_name']=htmlspecialchars($_POST['product_name']);        
                     
$date_post     $_POST['checkInYear']."-".$_POST['checkInMonth']."-".$_POST['checkInDay'];
                    
$query "INSERT INTO `tbl_act4_data`  "
                    
."(`id` ,`topic` ,`topic_en` ,`detail` ,`detail_en` ,`date_post`, `cate_id`  ,`first_page` , `date_start` , `refer_from`) "
                    
."VALUES "
                    
." ('' , '".$_POST['product_name']."', '".$_POST['product_name_en']."', '".$_POST['detailth']."', '".$_POST['detail_en']."', '".$date_post."' ,'".$_POST['cate_id']."', '0'  ,'".$_POST['sdate']."' ,'".$_POST['refer_from']."' ) ";
                    
mysql_query($query);
                    
$_POST['currentID']= mysql_insert_id();
            }
        
####################################################
        
if($_POST['action']=='update'){
             
$_POST['product_name']=htmlspecialchars($_POST['product_name']);    
              
$date_post     $_POST['checkInYear']."-".$_POST['checkInMonth']."-".$_POST['checkInDay'];
            
$query "UPDATE `tbl_act4_data` SET  "
                    
." `topic` ='".$_POST['product_name']."'  ,`topic_en` =  '".$_POST['product_name_en']."' "
                    
." ,`detail`='".$_POST['detailth']."' ,`detail_en`='".$_POST['detail_en']."' , `cate_id`= '".$_POST['selectCateID']."'   ,`date_post` =  '"$date_post."'  "
                    
." , `refer_from` ='".$_POST['refer_from']."' , `date_start` = '".$_POST['sdate']."'  WHERE id = '".$_POST['currentID']."'  ";  //selectCateID
            
mysql_query($query);
        }
        
        
####################################################
        
if($_POST['action2']=='addpic'){        
                    if(
$_FILES['uploadfile']['name']!=""){
                     
$tempFileName $_FILES['uploadfile']['name'];
                    
GetNewFileName($_FILES['uploadfile']['tmp_name'],&$_FILES['uploadfile']['name'],$i);
                    
move_uploaded_file($_FILES['uploadfile']['tmp_name'], $path_product.$_FILES['uploadfile']['name']);
                    
$query "INSERT INTO `tbl_act3_pic` "
                        
." (`id` ,`pic_name` ,`model_data_id`  ,`oldFilename`,`title_img` ) "
                        
." VALUES ('' , '".$_FILES['uploadfile']['name']."', '".$_POST['currentID']."' ,  '".$tempFileName."', '".$_POST['title_img']."') ";
                        
mysql_query($query);
                    }
        }    
        
####################################################
        
if($_POST['action2']=='addDoc'){        
                    if(
$_FILES['uploadfile2']['name']!=""){
                     
$tempFileName $_FILES['uploadfile2']['name'];
                    
GetNewFileName($_FILES['uploadfile2']['tmp_name'],&$_FILES['uploadfile2']['name'],$i);
                    
move_uploaded_file($_FILES['uploadfile2']['tmp_name'], $path_product.$_FILES['uploadfile2']['name']);
                    
$query "INSERT INTO `tbl_act3_doc` "
                        
." (`id` ,`pic_name` ,`model_data_id`  ,`oldFilename`,`title_img` ) "
                        
." VALUES ('' , '".$_FILES['uploadfile2']['name']."', '".$_POST['currentID']."' ,  '".$tempFileName."', '".$_POST['title_img']."') ";
                        
mysql_query($query);
                    }
        }            
        
####################################################        
        
if($_POST['action2']=='editText'){
                    
$query="UPDATE tbl_act3_pic SET title_img='".$_POST['title'][$_POST['dataID']]."' WHERE id = '".$_POST['dataID']."' ";
                    
mysql_query($query);
            }
    
        
####################################################
        
if($_POST['currentID']){
                
$query "SELECT * FROM tbl_act4_data WHERE id = '".$_POST['currentID']."' ";
                
$result mysql_query($query);
                
$currentData=mysql_fetch_assoc($result);
                
$cate_id  =$currentData['cate_id'];
                
$dateStartArray=explode("-",$currentData['date_start']);
                
$CurrArray=explode("-",$currentData['date_post']);
                        
$currentDate=$CurrArray[2];
                        
$currentMonth=$CurrArray[1];
                        
$currentYear$CurrArray[0];    
                
$query "SELECT * FROM `tbl_act3_pic` WHERE model_data_id = '".$_POST['currentID']."' ORDER BY id  ";
                
$resultPic mysql_query($query);
                
$query "SELECT * FROM `tbl_act3_doc` WHERE model_data_id = '".$_POST['currentID']."' ORDER BY id  ";
                
$resultDocmysql_query($query);                

        }        
        
####################################################    


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="ajax.js"></script>
<script language="javascript">
                //--------------------------------        
            function  FormValid(){
                    if((document.form1.uploadfile.value=="")&&(document.form1.currID.value=="")){
                                 alert("กรุณาใส่ไฟล์ Banner  ");
                                return false;
                   }else {     
                            document.form1.action.value = 'Add';
                        }
                }
        //-----------------------------------------------    
        function GetSubCate(MainCateID, SubCate){
                var str=Math.random();
                    var isNS4 = (navigator.appName=="Netscape")?1:0;
                    var mydata='MainCateID='+MainCateID+'&SubCate='+SubCate+'&str='+str;    
                     ajax = new sack('getSubCate.php');
                    ajax.element ="showSubCate";
                    ajax.runAJAX(mydata)
    }
    //-------------------------------------------------
    function removePic(pic){
        if(confirm('ต้องการลบรุปนี้')){
                document.form1.RmPic.value=pic;
                document.form1.action.value='deletePic';
                document.form1.submit();
        }else{
                return false;
            }
    }
    //-------------------------------------------------
    function removeDoc(pic){
        if(confirm('ต้องการลบไฟล์นี้')){
                document.form1.RmPic.value=pic;
                document.form1.action.value='deleteDoc';
                document.form1.submit();
        }else{
                return false;
            }
    }    
</script>
</head>

<body>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post" name="form1" onSubmit="return FormValid();" enctype="multipart/form-data">
    <table width="100%" border="0" cellspacing="3" cellpadding="3">
  <tr>
    <td class="txt10-black">
      <table width="100%" border="0" cellspacing="1" cellpadding="3">
     <tr>
          <td width="100%" align="left" bgcolor="#ECECD9"><!--<a href="main.php?work=articleList"><img src="images/black_icon/16x16/br_prev.png" width="16" height="16" hspace="5" border="0" align="absmiddle" />Back  </a> --> &nbsp;&nbsp;<img src="images/black_icon/16x16/sq_plus.png" width="16" height="16" hspace="5" border="0" align="absmiddle" />เพิ่มข่าวด่วน</td>
          </tr>
     <tr>
       <td align="left">
       <!--8888888888888888888888888888 -->
       <form action="<?php $_SERVER['PHP_SELF']?>" method="post" name="form1" enctype="multipart/form-data">
<table width="100%" border="0" cellspacing="3" cellpadding="3">
  <tr>
        <td class="txt10-black"><table width="100%" border="0" cellspacing="2" cellpadding="2">
          <tr>
            <td width="22%" height="11" align="right">ชื่อหัวข้อ</td>
            <td width="78%"><span >
              <input name="product_name" type="text" id="product_name" size="60" value="<?php echo $currentData['topic']?>" />
            </span></td>
          </tr>

          <tr>
            <td height="25" align="right">รายละเอียด</td>
            <td><span >
              <textarea name="detailth" cols="55" rows="15" id="detailth"><?php echo $currentData['detail']?></textarea><script language="javascript1.2">
              generate_wysiwyg('detailth');
        </script>
            </span></td>
          </tr>
           <tr>
            <td height="25" align="right">วันที่</td>
            <td><select name="checkInDay" id="checkInDay">
              <?php for($i=1;$i<=31;$i++){ 
                            if(
$i<10){ $i"0".$i;}    
                
?>
              <option value="<?php echo $i?><?php if($currentDate==$i) echo "selected";?>><?php echo $i?></option>
              <?php ?>
            </select>
-
<select name="checkInMonth" id="checkInMonth">
  <?php
        
if($_POST['stopMonth']){  $currentMonth=$_POST['stopMonth'];}
        
reset($monthArray); 
        while(
$month=each($monthArray)){ ?>
  <option value="<?php echo $month['key']?><?php if($currentMonth==$month['key']) echo "selected";?>><?php echo $month['value']?></option>
  <?php }?>
</select>
-
<select name="checkInYear" id="checkInYear">
  <?php
  
if($_POST['stopYear']){ $currentYear=$_POST['stopYear']; }
  
$startYear=$currentYear-1; for($i=1;$i<3;$i++){ ?>
  <option value="<?php echo $startYear+$i?>"<?php if($startYear+$i==$currentYear) echo "selected";?>><?php echo ($startYear+$i)+543?></option>
  <?php ?>
</select></td>
          </tr>
         <!-- <tr>
            <td height="25" align="right">ที่มา</td>
            <td><span class="txt-8-red">
              <input name="refer_from" type="text" id="refer_from" size="50" value="<?php echo $currentData['refer_from']?>"  />
            ใส่ http://</span></td>
          </tr> -->
          <tr>
            <td height="25" align="right"><span >
            <input type="hidden" name="currentID" value="<?php echo $_POST['currentID']?>"/>
            <input type="hidden" name="RmPic" />
            </span></td>
            <td><span >
              <?php if($_POST['currentID']){?>
              <input name="Submit" type="submit"  value=" แก้ไขข้อมูล " onclick="form1.action.value='update'" />
              <?php }else{ ?>
              <input name="Submit" type="submit"  value=" เพิ่ม " onclick="form1.action.value='Add'" />
              <?php ?>
              <input name="action" type="hidden" id="action" />
            </span></td>
          </tr>
          <tr>
            <td height="25" align="right">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td height="25" colspan="2" align="center">&nbsp;</td>
          </tr>
      </table></td>
  </tr>
</table>

       <!--//8888888888888888888888888888 -->      
       </td>
     </tr>
      </table></td>
  </tr>
  </table>
 
</form>
</body>
</html>