<?php require_once('../Connections/BE2.php'); ?>
<?php
if (!isset($_SESSION)){ session_start(); }
   
if (isset($_POST["MM_update"])) {
   $idpath= sprintf("%07d",$_SESSION['login_memid'])."_".$_POST["adindex"] ;
   $wwwpath='/www2/skybni';
   $picpath= "/ecard/demo/d_".$idpath; 
   
   if($_POST["MM_update"] == "fp1"){
    $tfile="fileToUpload1";
    $imgext=$_POST['adpic'];
  
    if($_FILES[$tfile]["name"]<>''){
		   $ext= explode('.',$_FILES[$tfile]['name']) ;
	       $imgext=strtolower($ext[count($ext)-1]); //取最後一筆
		   $pic=$wwwpath.$picpath.".".$imgext;
		   move_uploaded_file($_FILES[$tfile]["tmp_name"],$pic);
    }  
	  
  $updateSQL = sprintf("UPDATE  mem_addemo SET addoc=%s, adpic=%s, adflag=%s , adlink=%s WHERE ad0=%s AND mid=%s",
                       GetSQLValueString($_POST['addoc'], "text"),
					   GetSQLValueString($imgext, "text"),
                       GetSQLValueString($_POST['adflag'], "text"),
					   GetSQLValueString($_POST['adlink'], "text"),
                       GetSQLValueString($_POST['ad0'], "int"), 
                       GetSQLValueString($_SESSION['login_memid'], "int"));

   mysql_select_db($database_BE2, $BE2);
   $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());
   $msg='更新完成....' ;
   $updateGoTo = "editecarddemo.html";
 
	echo "<script>alert('".$msg."');location.href='".$updateGoTo."';</script>";	
	  
   }  


}
 

$id=isset($_GET['id'])?$_GET['id']:'-1';
  
mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("SELECT * FROM mem_addemo WHERE mid=%s AND ad0 = %s", GetSQLValueString($_SESSION['login_memid'], "int"),GetSQLValueString($id, "int"));
$Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);
$totalRows_Rt2 = mysql_num_rows($Rt2);
?>

<div class="main ">
		 
			<div class="row">
				<div class="col-lg-12">
					<h3 class="page-header"><i class="fa fa-indent"></i>雲名片資料管理</h3>
					<ol class="breadcrumb">
						<li><i class="fa fa-home"></i><a href="index.html">首頁</a></li>
						<li><i class="fa fa-indent"></i>雲名片資料管理</li>				
					</ol>
				</div>
			</div>



			<div class="row">	
              <div class="col-sm-6">
			        <div class="panel panel-default">
			            <div class="panel-heading">
			                <h2><i class="fa fa-indent red"></i><strong>1.雲名片 廣告資料管理</strong></h2>
			            </div>
			            <div class="panel-body">
                        <h3> </h3>
                        <? $img=sprintf("/ecard/demo/d_%07d_%d.%s",$_SESSION['login_memid'],$row_Rt2["adindex"],$row_Rt2["adpic"]) ; 
						    
						   if(! file_exists("/www2/skybni".$img)){
							   $img='';
							   }
						
						  ?>
                         <img name="" width="250" src="<?= $img ?>"/>
                         
						 <form action="" method="post" name="fp1" id="fp1" enctype="multipart/form-data">
				                
                                
				                <div class="form-group">
				                    <label class="col-md-3 control-label" for="addoc">文字說明:</label>
				                    <div class="col-md-9">
				                  
                                    <input type="text" name="addoc" id="addoc" value="<?=  $row_Rt2['addoc']  ?>"  />
         
          
       
				                       <span class="help-block"> </span>
			                      </div>
		                       </div>
                               
                               <div class="form-group">
				                    <label class="col-md-3 control-label" for="addoc">連結:</label>
				                    <div class="col-md-9">
				                  
                                    <input type="text" name="adlink" id="adlink" value="<?=  $row_Rt2['adlink']  ?>"  />
         
          
       
				                       <span class="help-block"> </span>
			                      </div>
		                       </div>
                               

                               <div class="form-group">
				                    <label class="col-md-3 control-label" for="passwd1">使用</label>
				                    <div class="col-md-9">
				                    <label>
                                    <input type="radio" name="adflag" id="adflag" value="Y" style="WIDTH: 22px; HEIGHT: 22px" <?= ($row_Rt2['adflag']=='Y')?'checked="checked"':''; ?>/>
        <i></i> 啟用</label>
                                    <label>
                                    <input  type="radio" name="adflag" id="adflag" value="N" style="WIDTH: 22px; HEIGHT: 22px" <?= ($row_Rt2['adflag']=='N')?'checked="checked"':''; ?>/>
        <i></i> 停用</label>
				                       <span class="help-block"> </span>
			                      </div>
		                       </div>
                            
				             
                              
                              <div class="form-group"> 
                                <div class="col-md-9">
				                    
				                    <span class="help-block"></span>
	                                
                                </div>
		                    </div>
                             <div class="form-group">
				                    <label class="col-md-3 control-label" for="passwd1"> 上傳 廣告資料圖像</label>
				                    <div class="col-md-9">
                                    <input name="fileToUpload1" type="file" id="fileToUpload1" />
                                    <span class="help-block"> </span>
				                    </div>
				                </div>   
                              

				                <div class="form-group form-actions">
									<button type="submit" class="btn btn-primary">保存</button>
				                </div>
                          
                             
                    
                             <input type="hidden" name="MM_update" value="fp1" />
                             <input type="hidden" name="mid" id="mid" value="<?= $row_Rt2['mid'] ; ?>" />
                             <input type="hidden" name="ad0" id="ad0" value="<?= $row_Rt2['ad0'] ; ?>" />
						    
					       <span class="col-md-9">
						     <input type="hidden" name="adpic" id="adpic" value="<?= $row_Rt2['adpic'] ; ?>" />
					       </span>
						   <span class="col-md-9">
						   <input type="hidden" name="adindex" id="adindex" value="<?= $row_Rt2['adindex'] ; ?>" />
						   </span>
						 </form>
						</div>
			        </div>
			    </div>
		     </div>
		<!-- end: Content -->
		<br><br><br>
 
		<input type ="button" onclick="javascript:location.href='editecarddemo.html'" value="回到上一頁"></input> 
		
	</div>
    
 
 
	   <!-- end: Content -->
       <?php
mysql_free_result($Rt2);
?>
