<?php require_once('../Connections/BE2.php'); ?>
<?php
if (!isset($_SESSION)){ session_start(); }

  
   if(isset($_POST["MM_update"]) && ($_POST["MM_update"] == "fp1")){
  	 
	 $check_title=0;
	 
	 if($_POST['company_title']==''){ $check_title=0;}
	 else if($_POST['old_title']<>$_POST['company_title']){ 

		mysql_select_db($database_BE2, $BE2);
        $query_Rtc = sprintf("SELECT * FROM company WHERE company_title = %s", GetSQLValueString($_POST['company_title'], "text"));
        $Rtc = mysql_query($query_Rtc, $BE2) or die(mysql_error());
        $row_Rtc = mysql_fetch_assoc($Rtc);
        $totalRows_Rtc = mysql_num_rows($Rtc);
		if($totalRows_Rtc==0){
		   // make logo
		   $_GET['shopname']=trim($_POST['company_title']) ;
		   $_GET['shopid']=$_SESSION['login_memid'] ;
           //include('mk_webshop_logo.php');
		
		}else{ $check_title=1; }
		
		mysql_free_result($Rtc);
		 
	 } 
   
 if($check_title==0){  
  
  	
	
  //com_express	com_express_
  $updateSQL = sprintf("UPDATE company SET company_line=%s, company_title=%s, company_address=%s, company_mail=%s, company_tel=%s WHERE coid=%s",
                       GetSQLValueString($_POST['company_line'], "text"),
					   GetSQLValueString($_POST['company_title'], "text"),
					   GetSQLValueString($_POST['company_address'], "text"),
					   GetSQLValueString($_POST['company_mail'], "text"),
					   GetSQLValueString($_POST['company_tel'], "text"),
                       GetSQLValueString($_POST['coid'], "int")); //$_SESSION['login_memid']

   mysql_select_db($database_BE2, $BE2);
   $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());
   $msg='更新完成....' ;
 }else{ $msg='公司名稱重複....' ; }
    $updateGoTo = "webshopdev.html";
   
    echo '<script>alert("'.$msg.'");</script>';
	  
   } 
 
mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("SELECT * FROM company WHERE mid = %s", GetSQLValueString($_SESSION['login_memid'], "int"));
$Rt2 = mysql_query($query_Rt2, $BE2) or die(mysql_error());
$row_Rt2 = mysql_fetch_assoc($Rt2);
$totalRows_Rt2 = mysql_num_rows($Rt2);

$company_coid=$row_Rt2['coid'];

$q_up1 = sprintf("UPDATE member set coid='%s' WHERE coid = 0 AND mem_auto='%s' ", $company_coid, $_SESSION['login_memid']);
mysql_query($q_up1, $BE2) or die(mysql_error());

$img2='/www2/skybni/shop/ext/elogo_'.sprintf('%07d', $company_coid ).".png"; 
  

 if(! file_exists($img2)){
  //  $_GET['shopname']= '開發商網店'; 
    $_GET['shopid']=$company_coid; 
 	include 'mk_webshopdev_logo2.php'; 
	
 }
 

 // echo   $q_up1; 

/*
mysql_select_db($database_BE2, $BE2);
$query_Rt3 = sprintf("SELECT * FROM webshop WHERE coid= 1 OR coid='%s' order by coid,windex",$_SESSION['login_memid']) ; 
$Rt3 = mysql_query($query_Rt3, $BE2) or die(mysql_error());
$row_Rt3 = mysql_fetch_assoc($Rt3);
$totalRows_Rt3 = mysql_num_rows($Rt3);
$arr1=array();
$i=0;
do {   
    if($row_Rt3['coid']>1){ $i=$row_Rt3['windex']-1;}
    $arr1[$i][0]=$row_Rt3['wid']; 
	$arr1[$i][1]=$row_Rt3['coid'];
    $arr1[$i][2]=$row_Rt3['wtitle'];
    $arr1[$i][3]=$row_Rt3['wimg'].'.'.$row_Rt3['wimgext'];
	$arr1[$i][4]=$row_Rt3['wlink'];
	$arr1[$i][5]=$row_Rt3['wuse']; // can edit upload 
	$arr1[$i][6]=$row_Rt3['wflag']; // can edit upload 
	$i++;
 }  while ($row_Rt3 = mysql_fetch_assoc($Rt3));
 */
?>
<style>
     .box2{
         border-width:3px;
		 border-style:dashed;
		 border-color:#FFAC55;
		 padding:5px;
    } 
	
	img{
        max-width: 100%;
        max-height: 100%;
        display: block; /* remove extra space below image */
    }
    .box{
        width: 250px;        
        border: 5px solid black;
    }    
    .box.large{
        height: 300px;
    }
    .box.small{
        height: 100px;
    }
</style>

<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-list-alt"></i><a href="#">企業資料</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>網店資料管理</strong></h2>
			            </div>
			            <div class="panel-body">
 
                       
                         <h3 align="center">我的開發商網店連結<br><a href="/shopid/<?= $row_Rt2['coid']?>" target="_blank" title="開發商網店"> https://www.skybni.com.tw/shopid/<?= $row_Rt2['coid']?></a></h3>
						 <form action="" method="post" name="fop1" id="fop1" enctype="multipart/form-data">
	                               <div class="form-group">
				                    <label class="col-md-4 control-label" for="company_titleu">商店名稱Logo圖檔(上):</label>
			                    <div class="col-md-6"><input type="hidden" name="MM_update" value="fp1" />
				                      <input name="company_title" type="hidden" id="company_title" value="<?= $row_Rt2['company_title'] ; ?>" size="32" />   
                                      <input name="old_title" type="hidden" id="old_title" value="<?= $row_Rt2['company_title'] ; ?>" size="32" />

                                      <input name="company_titleu" type="text" id="company_titleu" value="<?= $row_Rt2['company_titleu'] ; ?>" size="32" />   
				                      <img id='img1' src="../shop/img/logo_<?= sprintf("%07d",$company_coid) ?>.png" /> 
		                        </div>
                                 <div class="col-md-2">
                                 <button type="button" class="btn btn-primary" onclick="mklogo_ud(1);">建立圖檔</button>
                                </div> 
	                       </div>  
                             <div class="form-group">
				                    <label class="col-md-4 control-label" for="company_titled">商店名稱Logo圖檔(下):</label>
		                       <div class="col-md-6">
				                      <input name="company_titled" type="text" id="company_titled" value="開發商網店" size="32" readonly="readonly" />   
				                       <img id='img2' src="../shop/ext/elogo_<?= sprintf("%07d",$company_coid) ?>.png" /> 
			                      </div>
                                  <div class="col-md-2">
                                 <button type="button" class="btn btn-primary" onclick="mklogo_ud(2);">建立圖檔</button>
                                </div>
                                  
	                       </div>          
  
                              
                              <div class="form-group"> 
                                
                                  <label class="col-md-4 control-label" for="company_address">Google 地圖:</label>
                                  
                                  <div class="col-md-8">
				                    <input name="company_address" type="text" id="company_address" value="<?= $row_Rt2['company_address'] ; ?>" size="28" />(輸入公司地址即可)
				                    <input name="company_pic" type="hidden" id="company_pic" value="<?= $row_Rt2['company_pic'] ; ?>"/>
			                      <span class="help-block"></span>
	                                
                                </div>
		                    </div>
                              
                              <div class="form-group"> 
                               	
                                  <label class="col-md-4 control-label" for="company_line">Line行動條碼:</label> 
                                <div class="col-md-8">
                                  <input name="company_line" type="text" id="company_line" value="<?= $row_Rt2['company_line'] ; ?>" size="28" />
                                </div>
		                    </div>
                             <div class="form-group"> 
                               	
                                  <label class="col-md-4 control-label" for="company_mail">公司_Email:</label> 
                                <div class="col-md-8">
                                  <input name="company_mail" type="text" id="company_mail" value="<?= $row_Rt2['company_mail'] ; ?>" size="28" />
                                </div>
		                    </div>
                            
                           <div class="form-group"> 
                               	
                                  <label class="col-md-4 control-label" for="company_tel">聯繫電話:</label> 
                                <div class="col-md-8">
                                  <input name="company_tel" type="text" id="company_tel" value="<?= $row_Rt2['company_tel'] ; ?>" size="28" />
                                  <br>
                                </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" id="coid" name="coid" value="<?= $row_Rt2['coid'] ; ?>" />

						    
						  </form>
						</div>
			        </div>
			    </div>
		     </div>
		<!-- end: Content -->
 
</div>		 
 
   
        
<script type="text/javascript">
 
 
function updata(i){
	
     window.location.href='editwebshop.html?id='+i;
	 
}
function mklogo_ud(i){
	 var title='';
	 var shopname=i;
	 
	 var id=<?=$company_coid ;?>;
	 if(i==1){
	 // $('#logo1').html('');	 
	   title=$('#company_titleu').val();
	  } else{
	  //  $('#logo2').html('');	  
	   title=$('#company_titled').val();
	  }
 
	  $.ajax({
		method: "POST",
		url: "ajax_makelogo_ud.php",
		//data: $('#yourformid').serialize(),
		data: {'id':id,'shopname':i,'title':title},
		datatype:"image/png" 
		}).done(function( data ) {
		// alert( data);
		 //if(data=="OK"){
			
			if(i==1){ 
			  // $('#img1').attr('src', url.createObjectURL(data));
		      // $("#img3").attr("src", url.createObjectURL(data));
			   $("#img1").attr("src", $("#img1").attr("src")+"?timestamp=" + new Date().getTime());	
		    }else{
			   $("#img2").attr("src", $("#img2").attr("src")+"?timestamp=" + new Date().getTime());	
		      // $('#img2').attr('src', url.createObjectURL(data));	
			  // $("#img3").attr("src", url.createObjectURL(data));	
			 }
			 alert('OK'); 
 		  // }
       });
	 
	 return false;
	
 }
 
 
</script> 
 
	   <!-- end: Content -->
       <?php
mysql_free_result($Rt2);
 
?>
