<?php require_once('../Connections/BE2.php'); ?>
<?php
if (!isset($_SESSION)){ session_start(); }

/*
	ad0
	mid	int(7)  master id		 
    adpic	varchar(4)	 pic ext
    addoc	varchar(120) pic doc	
    adflag	varchar(1)	 	N		 
    adindex  index
*/
 


if (isset($_POST["MM_update"])) {
   $idpath= sprintf("%07d",$_SESSION['login_memid']) ;
   $wwwpath='/www2/skybni';
   $picpath= "/ecard/img/user_".$idpath; 
   
   if($_POST["MM_update"] == "fp1"){
    $tfile="fileToUpload1";
    $mem_logo2=$_POST['mem_logo2'];
  
    if($_FILES[$tfile]["name"]<>''){
		   $ext= explode('.',$_FILES[$tfile]['name']) ;
	       $imgext=strtolower($ext[count($ext)-1]); //取最後一筆
		   $pic=$wwwpath.$picpath.".".$imgext;
		   $mem_logo2=$imgext;
		   move_uploaded_file($_FILES[$tfile]["tmp_name"],$pic);
    }  
	  
  $updateSQL = sprintf("UPDATE member SET mem_logo2_ck=%s, mem_search=%s, font_color=%s, mem_logo2=%s WHERE mem_auto=%s",
                       GetSQLValueString($_POST['mem_logo2_ck'], "text"),
					   GetSQLValueString($_POST['mem_search'], "text"),
                       GetSQLValueString($_POST['font_color'], "text"),
                       GetSQLValueString($mem_logo2, "text"), 
                       GetSQLValueString($_SESSION['login_memid'], "int"));

   mysql_select_db($database_BE2, $BE2);
   $Result1 = mysql_query($updateSQL, $BE2) or die(mysql_error());
   $msg='更新完成....' ;
   $updateGoTo = "editecarddemo.html";
 
//  $updateSQL = sprintf("UPDATE member SET mem_logo2_ck=%s, ck_search=%s, font_color=%s, mem_logo2=%s, company_name=%s, company_title=%s,mem_logo=%s WHERE mem_auto=%s",
  
    echo '<script>alert("'.$msg.'");</script>';
	  
   } else if($_POST["MM_update"] == "fp2"){
	   
 $updateSQL2 = sprintf("UPDATE member SET mem_title=%s,mem_user=%s,mem_user2=%s,mem_name_en=%s ,mem_mobile2=%s,mem_line=%s,mem_google=%s,mem_mail=%s WHERE mem_auto=%s",
	                   GetSQLValueString($_POST['mem_title'], "text"),
					   GetSQLValueString($_POST['mem_user'], "text"),
                       GetSQLValueString($_POST['mem_user2'], "text"), 
					   GetSQLValueString($_POST['mem_name_en'], "text"),
					   GetSQLValueString($_POST['mem_mobile2'], "text"), 
					   GetSQLValueString($_POST['mem_line'], "text"), 
					   GetSQLValueString($_POST['mem_google'], "text"), 
					   GetSQLValueString($_POST['mem_mail'], "text"),
                       GetSQLValueString($_SESSION['login_memid'], "int"));   
/*
nameS_ckS in /www2/skybni/guest/body_editecardfile.php on line 153

Notice: Undefined index: mem_name_ck in /www2/skybni/guest/body_editecardfile.php on line 155

Notice: Undefined index: mem_name_en_ck in /www2/skybni/guest/body_editecardfile.php on line 157
*/   
	  mysql_select_db($database_BE2, $BE2);
      $Result1 = mysql_query($updateSQL2, $BE2) or die(mysql_error());

	  $msg='更新完成....' ;
      $updateGoTo = "editecardfile.html";
	  echo '<script>alert("'.$msg.'");</script>'; 
    }


}


 //update `member` set company_title=mem_name WHERE mem_auto>10 and mem_auto<26
mysql_select_db($database_BE2, $BE2);
$query_Rt2 = sprintf("SELECT * FROM mem_addemo WHERE mid = %s order by adindex", 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);
if($totalRows_Rt2==0){
  mysql_free_result($Rt2);
 
  for($c=1;$c<9;$c++){	
  
  mysql_select_db($database_BE2, $BE2);
  $INS_Rt2 = sprintf("INSERT INTO mem_addemo(mid,adindex)VALUES(%s,%s)",$_SESSION['login_memid'],$c);
  mysql_query($INS_Rt2, $BE2) or die(mysql_error());
  
  }
 mysql_select_db($database_BE2, $BE2);
 $query_Rt2 = sprintf("SELECT * FROM mem_addemo WHERE mid = %s order by adindex", 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);
	
}

?>

<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-md-12">
					<div class="panel panel-default">
						<div class="panel-heading">
							<h2><i class="fa fa-list red"></i><span class="break"></span><strong> 廣告資料管理</strong></h2>
						</div>


						<div class="panel-body">

					<h3 class="panel-title">&nbsp;</h3>
					            <div class="clearfix"></div>  
                    
                     <div style="overflow:scroll;">
				 <table width="501" class="table table-striped table-bordered bootstrap-datatable datatable" style="min-width:800px;">
 
						<thead>
							<tr class="replace-inputs">
								<th width="51" class="center">#</th>
								<th width="117">序</th>
								<th width="173">說明</th>
								<th width="56">啟用</th>
								<th width="80">編輯</th>
							</tr>
						</thead>
						<tbody>
                           <?php  
							if($totalRows_Rt2>0){
							$i=0;	
						 do { $i++;?>
							<tr>
								<td class="center"><?= $row_Rt2['adindex'];?></td>
                                <td>
                                <? $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 ?>"/></td>
                                <td><?= $row_Rt2['addoc'];?></td>
                                <td><?= $row_Rt2['adflag'];?></td>
                                <td><a href="editecarddemo2-<?= $row_Rt2['ad0']; ?>.html" target="_self">編輯</a></td>
							</tr>
						
                        <?php } while ($row_Rt2 = mysql_fetch_assoc($Rt2));
							}
						  	?></tbody>
 
					</table>
							      
                   

                   </div>



					  </div>
					</div>
				</div><!--/col-->
			
			</div>


			
		<!-- end: Content -->
		<br><br><br>
		 
		 
		
	</div>
    
    

        
<script type="text/javascript">
 
 function found_pmem() {
  
   var pname=$('#pname').val();	
   $.ajax({
		method: "POST",
		url: "ajax_found_mynum.php",
		//data: $('#yourformid').serialize(),
		data: {'pname': pname}
		}).done(function( data ) {
 	     response = JSON.parse(data);
		 $('#pname').val(response.name);	
		 $('#mem_num').val(response.id);
		 if(response.id>1){ alert('找到推薦人..');}
		 else{ alert('找不到推薦人..'); }
		 
      });
 
   return false;
 };

function make_logo(i){
	  var title=$('#company_title').val();
	  alert(title);
	  $.ajax({
		method: "POST",
		url: "ajax_make_logo.php",
		//data: $('#yourformid').serialize(),
		data: {id: i}
		}).done(function( data ) {
		 if(data!="ERR"){
			$('#mylogo').html('<img name="logo" src="/logo_img/'+data +'" alt="1" />');	 
			 }	
		// $('#mylogo').html(data);	
	
      });
	  
	 return false;
	}
 
</script> 
 
	   <!-- end: Content -->
       <?php
mysql_free_result($Rt2);
?>
