/home/bjcompany/domains/benjabhorn.com/public_html/BJconcrete/control/bannert_add.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php
        
if(!$_GET['txtHead']){
                
$_GET['txtHead']="ข้อมูลโครงการ";
            }else{
                    
$_GET['txtHead']=$_GET['txtHead'];
                }
             
//---------------------------------------------------------
            
$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'];
            }
            if(
$_GET['currentTypeID']){
                    
$_POST['currentTypeID']=$_GET['currentTypeID'];
            }            
            
//-----------------------------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);    
            
##########################################################################    
            //echo $_POST['action']."  >> ".$_POST['toSort'];
    
if($_POST['action']=='Sort')
    {
         switch(
$_POST['toSort']) {
                case 
"up"  
                        
$numberUpDate=$_POST['number']-1;
                        
$query="UPDATE tbl_banner SET num = num+1 WHERE num='".$numberUpDate."'   ";
                        
//echo $query."<br>";
                        
mysql_query($query);
                        
$query="UPDATE tbl_banner SET num = num-1 WHERE id='".$_POST['EditID']."'     ";
                        
mysql_query($query);
                        
//echo $query."<br>";
                        
break;
                case 
"down"  
                        
$numberUpDate=$_POST['number']+1;
                        
$query="UPDATE tbl_banner SET num =num-1 WHERE num='".$numberUpDate."'   ";
                        
//echo $query."<br>";
                        
mysql_query($query);
                        
$query="UPDATE tbl_banner SET num =num+1 WHERE id='".$_POST['EditID']."'   ";
                        
mysql_query($query);    
                        
//echo $query."<br>";
                        
break;    
         }
        
    }
//end Sort

        ####################################################-
                //---------------------------UPDATE STATUS-------------------
        
if($_POST['action']=='updateStatus'){
                    
$_POST['date_start']=date("Y-m-d");
                    
$query="UPDATE tbl_banner SET banner_status ='".$_POST['first_page'][$_POST['EditID']]."'   WHERE id= '".$_POST['EditID']."'  ";
                    
mysql_query($query);
            }    
        
####################################################-DELETE IMAGEs FILE
            //---------------------------------------------------------------------
            
if($_POST['action2']=='DeleteBanner'){
                 if(
file_exists($path_product_thb.$_POST['RemoveFile'])){
                             @
unlink ($path_product_thb.$_POST['RemoveFile']);
                 }
                 if(
file_exists($path_product."/".$_POST['RmPic'])){
                             @
unlink ($path_product."/".$_POST['RmPic']);
                 }
                 
$query "DELETE FROM  tbl_banner  WHERE  id = '".$_POST['dataID']."' ";
                
// echo $query;
                // echo "<br>".$_POST['dataID'];
                
if( mysql_query($query)){
                            
//-------------resort-----------------------------------------number
                
$query="UPDATE  tbl_banner  SET num=num-1 WHERE  num > '".$_POST['number']."' AND banner_type='".$_GET['type']."'  ";
                
                 
mysql_query($query);
                 
?>
                                <script language="javascript">
                                    window.location.href='main.php?work=<?php echo $_GET['work']?>&type=<?php echo $_GET['type']?>&MenuID=<?php echo $_GET['MenuID']?>';
                                </script>
                        <?php 
                
}
            }    
        
######################### PROJECT PLAN  IMAGE############################
        
if($_POST['action']=='Add'){
                if(
$_POST['currentID']==''){
                    
$query="SELECT  MAX(num) Maxnum FROM tbl_banner  WHERE banner_type='".$_GET['type']."'   ";    
                    
$result=mysql_query($query);
                    
$max=mysql_fetch_assoc($result);
                    
$maxNum=$max['Maxnum']+1;
                    
                    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_banner` ( `id` ,`pic_name` ,`banner_type` ,`oldFilename` ,`title_img` ,`title_img2` "
                        
." ,`links` ,`banner_desc` ,`banner_status` ,`num`) "
                        
." VALUES ('', '".$_FILES['uploadfile']['name']."' , '".$_GET['type']."' , '".$tempFileName."', '".$_POST['title_img']."', '".$_POST['title_img2']."',  '".$_POST['links']."', '', '".$_POST['banner_status']."' , '".$maxNum."') ";
                        
mysql_query($query);
                }else{
                        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']);
                            @
unlink($path_product.$_POST['OldChkPic']);
                            @
unlink($path_product_thb.$_POST['OldChkPic']);
                        }else{
                                
$_FILES['uploadfile']['name']=$_POST['OldChkPic'];
                        }
                        
$query="UPDATE  `tbl_banner`  SET  `pic_name`= '".$_FILES['uploadfile']['name']."' ,`banner_type`='".$_GET['type']."' ,`oldFilename`= '".$tempFileName."' ,`title_img`='".$_POST['title_img']."' ,`title_img2` ='".$_POST['title_img2']."'  "
                        
." ,`links`  = '".$_POST['links']."' ,`banner_desc`='' ,`banner_status`='".$_POST['banner_status']."'  "
                        
." WHERE id = '".$_POST['currentID']."' ";
                        if(
mysql_query($query)){ ?>
                                <script language="javascript">
                                    window.location.href='main.php?work=<?php echo $_GET['work']?>&type=<?php echo $_GET['type']?>&MenuID=<?php echo $_GET['MenuID']?>';
                                </script>
                        <?php     }
                }
        }
    
        
####################################################-SELECTD DATA
                
$query="SELECT *  FROM  tbl_banner   WHERE  banner_type ='".$_GET['type']."'  ORDER BY num ASC";
                
$resultBanner=mysql_query($query);
                
$Xrow =mysql_num_rows($resultBanner);
        if(
$_GET['currentID']){
                
$query="SELECT *  FROM  tbl_banner   WHERE  id ='".$_GET['currentID']."'  ";
                
$result=mysql_query($query);
                
$currentData=mysql_fetch_assoc($result);
            }
?>

<!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(){
                            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, pictype){
        if(confirm('ต้องการลบรุปนี้')){
                document.form1.RmPic.value=pic;
                document.form1.action2.value=pictype;
                document.form1.submit();
        }else{
                return false;
            }
    }
    //-------------------------------------------------
    function removeDoc(pic){
        if(confirm('ต้องการลบไฟล์นี้')){
                document.form1.RmPic.value=pic;
                document.form1.action2.value='deleteDoc';
                document.form1.submit();
        }else{
                return false;
            }
    }    
    //----------------------------------------
            function DeleteThis(ids,filename,num){
                    if(confirm('ต้องการลบรายการนี้ ?')){
                                document.form2.action2.value='DeleteBanner';
                                document.form2.dataID.value=ids;
                                document.form2.RemoveFile.value=filename;            
                                document.form2.number.value=num;                        
                                document.form2.submit();                        
                        }else{
                               return false;
                            }
            }
        //---------------------    
                function sortThis(number, toSort , ids , subcateID ){
                          document.form1.number.value=number;
                        document.form1.toSort.value=toSort;
                        document.form1.EditID.value=ids;
                        document.form1.subcateID.value=subcateID;                        
                        document.form1.action.value='Sort';
                        document.form1.submit();
          }
          //--------------------------------------------------
            function DeleteThis2(ids){
                       if(confirm('ตอ้งการลบรายการนี้')){
                                document.form1.action.value = 'delete';
                                document.form1.ids.value = ids;
                                document.form1.submit();
                        }
       }
        
</script>
<style type="text/css">
.buttonHead {
    -moz-box-shadow:inset 0px 1px 0px 0px #f29c93;
    -webkit-box-shadow:inset 0px 1px 0px 0px #f29c93;
    box-shadow:inset 0px 1px 0px 0px #f29c93;
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #fe1a00), color-stop(1, #ce0100) );
    background:-moz-linear-gradient( center top, #fe1a00 5%, #ce0100 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#fe1a00', endColorstr='#ce0100');
    background-color:#fe1a00;
    -moz-border-radius:4px;
    -webkit-border-radius:4px;
    border-radius:4px;
    border:1px solid #d83526;
    display:inline-block;
    color:#ffffff;
    font-family:Arial;
    font-size:11px;
    font-weight:bold;
    padding:4px 15px;
    text-decoration:none;
}.buttonHead:hover {
    background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ce0100), color-stop(1, #fe1a00) );
    background:-moz-linear-gradient( center top, #ce0100 5%, #fe1a00 100% );
    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ce0100', endColorstr='#fe1a00');
    background-color:#ce0100;
}.buttonHead:active {
    position:relative;
    top:1px;
}
/* This imageless css button was generated by CSSButtonGenerator.com */
</style>

</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="3%" align="left" bgcolor="#D9D9B3">&nbsp;&nbsp;<img src="images/black_icon/16x16/app_window.png" alt="" width="16" height="16" /></td>
              <td width="97%" align="left" bgcolor="#D9D9B3" class="red"><?php if($_GET['type']==1){?>
เพิ่ม banner
  <?php } else{?>
เพิ่มลิงค์อื่นๆ
<?php }?></td>
          </tr>
     <tr>
       <td colspan="2" align="left"><table width="100%" border="0" cellpadding="3" cellspacing="3" class="txt10-black">
        <?php if($_GET['type']==1){?> <tr>
           <td width="22%" height="-2" align="right">ไฟล์ banner</td>
           <td width="78%" align="left" class="txt-8-red"><span class="red">
           <?php
             
if($_GET['currentID']){ ?><img src="<?php echo $path_product_thb.$currentData['pic_name']?>" border =0>
             <br />
             <?php }?>
             <input name="uploadfile" type="file" id="uploadfile" size="20" />
             <br />
             *.png , *.jpg ขนาดกว้าง 1000 pixel สุง 532 pixel
           </span></td>
         </tr>  <?php }?>
     
        <!-- <tr>
           <td height="-3" align="right">หัวข้อ</td>
           <td width="78%" align="left" class="txt-8-red"><input name="title_img" type="text" id="title_img" value="<?php echo $currentData['title_img']?>" size="50" /></td>
         </tr> -->
       
         <tr>
           <td height="-2" align="right">link</td>
           <td width="78%" align="left" class="txt-8-red"><input name="links" type="text" id="links" size="50" maxlength="100" value="<?php echo $currentData['links']?>" />
             **ใส่ http://</td>
         </tr>
         <tr>
           <td height="-2" align="right">แสดงผล</td>
           <td width="78%" align="left" class="h1"> <select name="banner_status" id="first_page">
                 <option value="1" <?php if($currentData['banner_status']=='1') echo "selected";?>>แสดงทันที</option>
                 <option value="0" <?php if($currentData['banner_status']=='0') echo "selected";?>>ไม่แสดง</option>
             </select></td>
         </tr>
         <tr>
           <td height="25" align="right">&nbsp;
             <input type="hidden" name="OldChkPic"  value="<?php echo $currentData['pic_name']?>" />
             <input type="hidden" name="action" id="action" value="Add" />
             <input type="hidden" name="currentID" id="currentID" value="<?php echo $_GET['currentID']?>" />
             <input type="hidden" name="banner_type"  value="<?php echo $_POST['type']?>" />     
             
             
             <input type="hidden" name="ids" id="ids" />
            <input type="hidden" name="number"  />
            <input type="hidden" name="toSort" />                       
            <input type="hidden" name="EditID" /> 
            <input type="hidden" name="subcateID" />     
             </td>
           <td height="25" align="left"><span class="NAV_URL">
             <input name="Button2" type="submit" value=" เพิ่ม/แก้ไข ข้อมูล"  /></td>
         </tr>
         <tr>
           <td height="25" colspan="2" align="left"><br /></td>
           </tr>
         <tr>
           <td height="25" colspan="2" align="left" bgcolor="#EEEEEE"><img src="images/black_icon/16x16/picture.png" width="16" height="16" hspace="3" vspace="3" align="absmiddle" /></td>
         </tr>
         <tr>
           <td height="25" colspan="2" align="left">

           <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <?php $n=1; while($pic=mysql_fetch_assoc($resultBanner)){  
                    
                                    
$n_width=500;$n_height=266;
                                    
$fix_width=800$fix_height=426;
                                    
$info =  pathinfo($path_product."/".$pic['pic_name']);
                                    
$info[extension]=strtolower($info[extension]);
                                        if((
$info[extension]=='pjpeg')  || ($info[extension]=='gif')  ||  ($info[extension]=='png')  ||  ($info[extension]=='x-png') || ($info[extension]=='jpeg') || ($info[extension]=='jpg')){
                                    
// if(!file_exists($path_product_thb.$pic['pic_name'])){ 
                                        
list($width$height$type$attr) = getimagesize($path_product.$pic['pic_name']);
                                        
create_thub($path_product."/",$pic['pic_name'],$n_width,$n_height);
                                        
create_fix($path_product,$pic['pic_name'],$fix_width,$fix_height);
                                    
// }    
                            
                        
}
                        
                if(
$n%2) { $bgcolor='#EEEEDD';}else{ $bgcolor='#FFFFFF';}         
            
?>
             <tr bgcolor="<?php echo $bgcolor?>">
               <td width="4%" align="center">&nbsp;<img src="images/black_icon/16x16/brackets.png" width="16" height="16" /></a></td>
               <td width="64%">&nbsp;
               <?php if($pic['pic_name']){ ?><img src="<?php echo $path_product_thb.$pic['pic_name']?>" /><?php ?>
               <?php echo $pic['title_img']?></td>
               <td width="5%" align="center"><a href="<?php echo $pic['links']?>" target="_blank" title="<?php echo $pic['links']?>"><img src="images/black_icon/16x16/link.png" width="16" height="16" style="border:none" /></a></td>
               <td width="3%"><?php if($pic['num']>1){?>
                 <a href="javascript:void(0)" onClick="sortThis('<?php echo $pic['num'];?>', 'up' , '<?php echo $pic['id'];?>','<?php echo $pic['mainCateId'];?>' )"> <img src="images/black_icon/16x16/sq_br_up.png" width="16" height="16" border="0" /></a>
                 <?php ?></td>
               <td width="3%"><?php if($Xrow $pic['num']){?>
                 <a href="javascript:void(0)" onClick="sortThis('<?php echo $pic['num'];?>', 'down' , '<?php echo $pic['id'];?>','<?php echo $pic['mainCateId'];?>' )"> <img src="images/black_icon/16x16/sq_br_down.png" width="16" height="16" border="0" /></a>
                 <?php ?></td>
               <td width="13%" align="center"><select name="first_page[<?php echo $pic['id']?>]"  onchange="document.form1.action.value='updateStatus';document.form1.EditID.value='<?php echo $pic['id']?>';document.form1.submit();">
                 <option value="1" <?php if($pic['banner_status']=='1') echo "selected";?>>แสดงทันที</option>
                 <option value="0" <?php if($pic['banner_status']=='0') echo "selected";?>>ไม่แสดง</option>
               </select></td>
                <td width="3%" align="center">
                <a href="main.php?work=<?php echo $_GET['work']?>&type=<?php echo $_GET['type']?>&MenuID=<?php echo $_GET['MenuID']?>&currentID=<?php echo $pic['id']?>" title="แก้ไข banner">
                <img src="images/black_icon/16x16/doc_edit.png" width="16" height="16" border="0" /></a>
                </td>
               <td width="5%" align="center"><a href="javascript:void(0)" onClick="DeleteThis('<?php echo $pic['id']?>','<?php echo $pic['pic_name']?>','<?php echo $pic['num']?>')" title="ลบ รายการนี้"><img src="images/black_icon/16x16/delete.png" width="16" height="16" border="0" /></a></td>
              
             </tr>
             <?php $n++; } ?>
           </table>
           </td>
         </tr>
         <tr>
           <td height="25" colspan="2" align="left">&nbsp;</td>
         </tr>
       
       </table></td>
     </tr>
      </table></td>
  </tr>
  </table>
</form>
<form action="<?php $_SERVER['PHP_SELF']?>" method="post" name="form2">
    <input type="hidden" name="action2" />
    <input type="hidden" name="RemoveFile" /> 
     <input type="hidden" name="dataID" />  
        <input type="hidden" name="number" />       
</form>
            
</body>
</html>